From c8809df4c444f7c0f0b9b13e05aaa1fb1ca898bc Mon Sep 17 00:00:00 2001 From: Henry Harder Date: Fri, 23 Aug 2019 12:34:59 -0700 Subject: [PATCH 1/2] go-kosu: fixing witness issues --- packages/go-kosu/witness/witness.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/go-kosu/witness/witness.go b/packages/go-kosu/witness/witness.go index e31ba987..7b47bc8a 100644 --- a/packages/go-kosu/witness/witness.go +++ b/packages/go-kosu/witness/witness.go @@ -11,6 +11,7 @@ import ( "go-kosu/abci" "go-kosu/abci/types" + "go-kosu/store" ) // EventHandler is a callback that handles EventEmitterKosuEvent @@ -160,11 +161,14 @@ func (w *Witness) broadcastTxSync(tx interface{}, args []interface{}) { } func (w *Witness) handlePosterRegistryUpdate(e *EventEmitterKosuEvent) { + // offset by 12 because the 20 byte address is packed into 32 bytes + address, _ := store.NewAddress(e.Data[0][12:]) + tx := &types.TransactionWitness{ Subject: types.TransactionWitness_POSTER, Amount: types.NewBigInt(e.Data[1][:]), Block: e.Raw.BlockNumber, - Address: e.Raw.Address.String(), + Address: address.String(), } w.broadcastTxSync(tx, []interface{}{ @@ -174,11 +178,14 @@ func (w *Witness) handlePosterRegistryUpdate(e *EventEmitterKosuEvent) { } func (w *Witness) handleValidatorRegistryUpdate(e *EventEmitterKosuEvent) { + // offset by 12 because the 20 byte address is packed into 32 bytes + address, _ := store.NewAddress(e.Data[1][12:]) + tx := &types.TransactionWitness{ Subject: types.TransactionWitness_VALIDATOR, Block: e.Raw.BlockNumber, PublicKey: e.Data[0][:], - Address: hex.EncodeToString(e.Data[1][:]), + Address: address.String(), Amount: types.NewBigInt(e.Data[2][:]), } @@ -198,7 +205,7 @@ func (w *Witness) handleBlocks(ctx context.Context) error { // If it's the first block || round has ended if (num == 0 && (cur > w.initHeight)) || mat >= w.roundInfo.EndsAt { - if err := w.rebalance(num, cur); err != nil { + if err := w.rebalance(num, mat); err != nil { w.log.Error("rebalance", "err", err) } } From c1a9fa4fdd670700ddd308e156c387f51b3e3ac0 Mon Sep 17 00:00:00 2001 From: Gustavo Chain Date: Tue, 27 Aug 2019 09:47:59 +0200 Subject: [PATCH 2/2] go-kosu: panic on invalid address --- packages/go-kosu/witness/witness.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/go-kosu/witness/witness.go b/packages/go-kosu/witness/witness.go index 7b47bc8a..f79c9d10 100644 --- a/packages/go-kosu/witness/witness.go +++ b/packages/go-kosu/witness/witness.go @@ -162,7 +162,10 @@ func (w *Witness) broadcastTxSync(tx interface{}, args []interface{}) { func (w *Witness) handlePosterRegistryUpdate(e *EventEmitterKosuEvent) { // offset by 12 because the 20 byte address is packed into 32 bytes - address, _ := store.NewAddress(e.Data[0][12:]) + address, err := store.NewAddress(e.Data[0][12:]) + if err != nil { + panic(err) + } tx := &types.TransactionWitness{ Subject: types.TransactionWitness_POSTER,