From 9481cabd5011b5b8cb51e1467aa033de93845797 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 6 Jun 2018 20:45:20 -0700 Subject: [PATCH] fixes from review --- consensus/replay.go | 6 ++++-- p2p/pex/pex_reactor.go | 2 +- types/protobuf.go | 31 +++++++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/consensus/replay.go b/consensus/replay.go index c0c300b37..13ec9e403 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -280,7 +280,9 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight return nil, err } - // update the state + // if the app returned validators + // or consensus params, update the state + // with the them if len(res.Validators) > 0 { vals, err := types.PB2TM.Validators(res.Validators) if err != nil { @@ -289,7 +291,7 @@ func (h *Handshaker) ReplayBlocks(state sm.State, appHash []byte, appBlockHeight state.Validators = types.NewValidatorSet(vals) } if res.ConsensusParams != nil { - // TODO + state.ConsensusParams = types.PB2TM.ConsensusParams(res.ConsensusParams) } sm.SaveState(h.stateDB, state) } diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 457e54278..27ed422c5 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -267,7 +267,7 @@ func (r *PEXReactor) receiveRequest(src Peer) error { now := time.Now() minInterval := r.minReceiveRequestInterval() if now.Sub(lastReceived) < minInterval { - return fmt.Errorf("Peer (%v) send next PEX request too soon. lastReceived: %v, now: %v, minInterval: %v. Disconnecting", + return fmt.Errorf("Peer (%v) sent next PEX request too soon. lastReceived: %v, now: %v, minInterval: %v. Disconnecting", src.ID(), lastReceived, now, diff --git a/types/protobuf.go b/types/protobuf.go index 90ec8dab3..eb684ae7d 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -38,7 +38,7 @@ func (tm2pb) Header(header *Header) abci.Header { Time: header.Time.Unix(), NumTxs: int32(header.NumTxs), // XXX: overflow - TotalTxs: header.NumTxs, + TotalTxs: header.TotalTxs, LastBlockHash: header.LastBlockID.Hash, ValidatorsHash: header.ValidatorsHash, @@ -48,6 +48,7 @@ func (tm2pb) Header(header *Header) abci.Header { } } +// XXX: panics on unknown pubkey type func (tm2pb) Validator(val *Validator) abci.Validator { return abci.Validator{ Address: val.PubKey.Address(), @@ -56,6 +57,8 @@ func (tm2pb) Validator(val *Validator) abci.Validator { } } +// XXX: panics on nil or unknown pubkey type +// TODO: add cases when new pubkey types are added to go-crypto func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey { switch pk := pubKey.(type) { case crypto.PubKeyEd25519: @@ -73,6 +76,7 @@ func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey { } } +// XXX: panics on nil or unknown pubkey type func (tm2pb) Validators(vals *ValidatorSet) []abci.Validator { validators := make([]abci.Validator, len(vals.Validators)) for i, val := range vals.Validators { @@ -101,6 +105,7 @@ func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams { // ABCI Evidence includes information from the past that's not included in the evidence itself // so Evidence types stays compact. +// XXX: panics on nil or unknown pubkey type func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci.Evidence { _, val := valSet.GetByAddress(ev.Address()) if val == nil { @@ -113,7 +118,8 @@ func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci. switch ev.(type) { case *DuplicateVoteEvidence: evType = ABCIEvidenceTypeDuplicateVote - case *MockGoodEvidence, MockGoodEvidence: + case MockGoodEvidence: + // XXX: not great to have test types in production paths ... evType = ABCIEvidenceTypeMockGood default: panic(fmt.Sprintf("Unknown evidence type: %v %v", ev, reflect.TypeOf(ev))) @@ -128,6 +134,7 @@ func (tm2pb) Evidence(ev Evidence, valSet *ValidatorSet, evTime time.Time) abci. } } +// XXX: panics on nil or unknown pubkey type func (tm2pb) ValidatorFromPubKeyAndPower(pubkey crypto.PubKey, power int64) abci.Validator { pubkeyABCI := TM2PB.PubKey(pubkey) return abci.Validator{ @@ -192,3 +199,23 @@ func (pb2tm) Validators(vals []abci.Validator) ([]*Validator, error) { } return tmVals, nil } + +func (pb2tm) ConsensusParams(csp *abci.ConsensusParams) ConsensusParams { + return ConsensusParams{ + BlockSize: BlockSize{ + MaxBytes: int(csp.BlockSize.MaxBytes), // XXX + MaxTxs: int(csp.BlockSize.MaxTxs), // XXX + MaxGas: csp.BlockSize.MaxGas, + }, + TxSize: TxSize{ + MaxBytes: int(csp.TxSize.MaxBytes), // XXX + MaxGas: csp.TxSize.MaxGas, + }, + BlockGossip: BlockGossip{ + BlockPartSizeBytes: int(csp.BlockGossip.BlockPartSizeBytes), // XXX + }, + // TODO: EvidenceParams: EvidenceParams{ + // MaxAge: int(csp.Evidence.MaxAge), // XXX + // }, + } +}