diff --git a/acm/validator/ring.go b/acm/validator/ring.go index 635caed51296c89c6873bba2b329347970488b67..73ff93d632434d71336ec537f09122b87fed2cc0 100644 --- a/acm/validator/ring.go +++ b/acm/validator/ring.go @@ -21,6 +21,8 @@ type Ring struct { head int64 // Number of buckets size int64 + // Number of buckets populated + populated int64 } var big1 = big.NewInt(1) @@ -158,6 +160,9 @@ func (vc *Ring) Rotate() (totalPowerChange *big.Int, totalFlow *big.Int, err err vc.flow = NewSet() // Subtract the previous bucket total power so we can add on the current buckets power after this totalPowerChange = new(big.Int).Sub(vc.Cum().TotalPower(), vc.cum[vc.index(-1)].TotalPower()) + if vc.populated < vc.size { + vc.populated++ + } return } @@ -165,8 +170,11 @@ func (vc *Ring) CurrentSet() *Set { return vc.cum[vc.head] } -func (vc *Ring) PreviousSet() *Set { - return vc.cum[vc.index(-1)] +func (vc *Ring) PreviousSet(delay int64) *Set { + if delay > vc.populated { + delay = vc.populated + } + return vc.cum[vc.index(-delay)] } func (vc *Ring) Cum() *Set { diff --git a/bcm/blockchain.go b/bcm/blockchain.go index 1a146d42da5290e8b03691c35a44ad9df979f851..3e48d88f6df5b8949e3875fa868c950e4de3c985 100644 --- a/bcm/blockchain.go +++ b/bcm/blockchain.go @@ -275,10 +275,10 @@ func (bc *Blockchain) CurrentValidators() *validator.Set { return bc.validatorCache.CurrentSet() } -func (bc *Blockchain) PreviousValidators() *validator.Set { +func (bc *Blockchain) PreviousValidators(delay int) *validator.Set { bc.RLock() defer bc.RUnlock() - return bc.validatorCache.PreviousSet() + return bc.validatorCache.PreviousSet(int64(delay)) } func (bc *Blockchain) NumValidators() int { diff --git a/consensus/tendermint/abci/app.go b/consensus/tendermint/abci/app.go index 9a4982f419b5b0841788f93fe92b342ac455df8c..8df560137dfa0c12a1e7084d7931680fe8fe8da8 100644 --- a/consensus/tendermint/abci/app.go +++ b/consensus/tendermint/abci/app.go @@ -94,7 +94,8 @@ func (app *App) InitChain(chain abciTypes.RequestInitChain) (respInitChain abciT len(chain.Validators), app.blockchain.NumValidators())) } for _, v := range chain.Validators { - err := app.checkValidatorMatches(app.blockchain.Validators(), v) + pk, err := crypto.PublicKeyFromABCIPubKey(v.GetPubKey()) + err = app.checkValidatorMatches(app.blockchain.Validators(), abciTypes.Validator{Address: pk.Address().Bytes(), Power: v.Power}) if err != nil { panic(err) } @@ -113,13 +114,13 @@ func (app *App) BeginBlock(block abciTypes.RequestBeginBlock) (respBeginBlock ab if block.Header.Height > 1 { var err error // Tendermint runs a block behind with the validators passed in here - previousValidators := app.blockchain.PreviousValidators() - if len(block.LastCommitInfo.Validators) != previousValidators.Count() { - err = fmt.Errorf("Tendermint passes %d validators to BeginBlock but Burrow's Blockchain has %d", - len(block.LastCommitInfo.Validators), previousValidators.Count()) + previousValidators := app.blockchain.PreviousValidators(2) + if len(block.LastCommitInfo.Votes) != previousValidators.Count() { + err = fmt.Errorf("Tendermint passes %d validators to BeginBlock but Burrow's Blockchain has %d/ %v", + len(block.LastCommitInfo.Votes), previousValidators.Count(), previousValidators.String()) panic(err) } - for _, v := range block.LastCommitInfo.Validators { + for _, v := range block.LastCommitInfo.Votes { err = app.checkValidatorMatches(previousValidators, v.Validator) if err != nil { panic(err) @@ -217,13 +218,12 @@ func txExecutor(name string, executor execution.BatchExecutor, txDecoder txs.Dec } func (app *App) EndBlock(reqEndBlock abciTypes.RequestEndBlock) abciTypes.ResponseEndBlock { - var validatorUpdates abciTypes.Validators + var validatorUpdates []abciTypes.ValidatorUpdate app.blockchain.PendingValidators().Iterate(func(id crypto.Addressable, power *big.Int) (stop bool) { app.logger.InfoMsg("Updating validator power", "validator_address", id.Address(), "new_power", power) - validatorUpdates = append(validatorUpdates, abciTypes.Validator{ - Address: id.Address().Bytes(), - PubKey: id.PublicKey().ABCIPubKey(), + validatorUpdates = append(validatorUpdates, abciTypes.ValidatorUpdate{ + PubKey: id.PublicKey().ABCIPubKey(), // Must ensure power fits in an int64 during execution Power: power.Int64(), }) diff --git a/consensus/tendermint/node_view.go b/consensus/tendermint/node_view.go index 50b0b900fd96ee077020108bb7cfe44322038eef..8df94fc7f1852f8f5320594fc1f8b27b6c8b0168 100644 --- a/consensus/tendermint/node_view.go +++ b/consensus/tendermint/node_view.go @@ -68,7 +68,7 @@ func (nv *NodeView) RunID() simpleuuid.UUID { // Pass -1 to get all available transactions func (nv *NodeView) MempoolTransactions(maxTxs int) ([]*txs.Envelope, error) { var transactions []*txs.Envelope - for _, txBytes := range nv.tmNode.MempoolReactor().Mempool.Reap(maxTxs) { + for _, txBytes := range nv.tmNode.MempoolReactor().Mempool.ReapMaxTxs(maxTxs) { txEnv, err := nv.txDecoder.DecodeTx(txBytes) if err != nil { return nil, err diff --git a/consensus/tendermint/tendermint.go b/consensus/tendermint/tendermint.go index 918d2eee1b78fc1895a84e19af321b09eeed70e4..bdd99b866a01de585d54cba267ea207da4a53b46 100644 --- a/consensus/tendermint/tendermint.go +++ b/consensus/tendermint/tendermint.go @@ -55,9 +55,14 @@ func NewNode(conf *config.Config, privValidator tmTypes.PrivValidator, genesisDo return nil, err } + nodeKey, err := p2p.LoadOrGenNodeKey(conf.NodeKeyFile()) + if err != nil { + return nil, err + } + nde := &Node{} nde.Node, err = node.NewNode(conf, privValidator, - proxy.NewLocalClientCreator(app), + nodeKey, proxy.NewLocalClientCreator(app), func() (*tmTypes.GenesisDoc, error) { return genesisDoc, nil }, @@ -81,12 +86,16 @@ func DeriveGenesisDoc(burrowGenesisDoc *genesis.GenesisDoc) *tmTypes.GenesisDoc Power: int64(validator.Amount), } } + consensusParams := tmTypes.DefaultConsensusParams() + // Default limit is 10KiB. Raise his to 1MiB + consensusParams.TxSize.MaxBytes = 1024 * 1024 + return &tmTypes.GenesisDoc{ ChainID: burrowGenesisDoc.ChainID(), GenesisTime: burrowGenesisDoc.GenesisTime, Validators: validators, AppHash: burrowGenesisDoc.Hash(), - ConsensusParams: tmTypes.DefaultConsensusParams(), + ConsensusParams: consensusParams, } } diff --git a/execution/exec/block_execution.go b/execution/exec/block_execution.go index 15b35d8b016181f51465495641d1be25ed0078be..febf4199dd69ab84a40137d8ebb61ee7c9481944 100644 --- a/execution/exec/block_execution.go +++ b/execution/exec/block_execution.go @@ -73,7 +73,7 @@ func BlockHeaderFromHeader(header *abciTypes.Header) *BlockHeader { bs, _ := json.Marshal(header) return &BlockHeader{ JSON: string(bs), - NumTxs: header.NumTxs, + NumTxs: int32(header.NumTxs), } }