Skip to content

Commit

Permalink
broadcast newly finalized block (ethereum#43)
Browse files Browse the repository at this point in the history
* fix validator set recovery after restart

* broadcast newly finalized block

Co-authored-by: Qi Zhou <qzhou64@gmail.com>
  • Loading branch information
qizhou and Qi Zhou authored Mar 10, 2022
1 parent 87afa7f commit c5c965b
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
9 changes: 7 additions & 2 deletions consensus/tendermint/adapter/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
)

type Store struct {
chain *core.BlockChain
verifyHeaderFunc func(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error
makeBlock func(parentHash common.Hash, coinbase common.Address, timestamp uint64) (block *types.Block, err error)
mux *event.TypeMux
}

func NewStore(
chain *core.BlockChain,
verifyHeaderFunc func(chain consensus.ChainHeaderReader, header *types.Header, seal bool) error,
makeBlock func(parentHash common.Hash, coinbase common.Address, timestamp uint64) (block *types.Block, err error)) *Store {
return &Store{chain: chain, verifyHeaderFunc: verifyHeaderFunc, makeBlock: makeBlock}
makeBlock func(parentHash common.Hash, coinbase common.Address, timestamp uint64) (block *types.Block, err error),
mux *event.TypeMux) *Store {
return &Store{chain: chain, verifyHeaderFunc: verifyHeaderFunc, makeBlock: makeBlock, mux: mux}
}

func (s *Store) Base() uint64 {
Expand Down Expand Up @@ -71,6 +74,8 @@ func (s *Store) SaveBlock(block *types.FullBlock, commit *types.Commit) {
if n == 0 || err != nil {
log.Warn("SaveBlock", "n", n, "err", err)
}

s.mux.Post(core.NewMinedBlockEvent{Block: block.WithCommit(commit).Block})
}

func (s *Store) ValidateBlock(state pbft.ChainState, block *types.FullBlock) (err error) {
Expand Down
2 changes: 2 additions & 0 deletions consensus/tendermint/gov/gov.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ func (g *Governance) GetValidatorSets(height uint64) (*types.ValidatorSet, *type
}

// GetValidatorSet returns the validator set of a height

func (g *Governance) GetValidatorSet(height uint64, lastVals *types.ValidatorSet) *types.ValidatorSet {
if height == 0 {
return &types.ValidatorSet{}
}

idxInEpoch := (height - 1) % g.config.Epoch

if idxInEpoch != 0 && lastVals != nil {
// use cached version if we do not have a validator change
cvals := lastVals.Copy()
Expand Down
5 changes: 3 additions & 2 deletions consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -131,7 +132,7 @@ func (c *Tendermint) P2pServer() *libp2p.Server {
return c.p2pserver
}

func (c *Tendermint) Init(chain *core.BlockChain, makeBlock func(parent common.Hash, coinbase common.Address, timestamp uint64) (*types.Block, error)) (err error) {
func (c *Tendermint) Init(chain *core.BlockChain, makeBlock func(parent common.Hash, coinbase common.Address, timestamp uint64) (*types.Block, error), mux *event.TypeMux) (err error) {
// Outbound gossip message queue
sendC := make(chan pbftconsensus.Message, 1000)

Expand All @@ -144,7 +145,7 @@ func (c *Tendermint) Init(chain *core.BlockChain, makeBlock func(parent common.H
c.rootCtx = rootCtx

// datastore
store := adapter.NewStore(chain, c.VerifyHeader, makeBlock)
store := adapter.NewStore(chain, c.VerifyHeader, makeBlock, mux)

// p2p key
if TestMode {
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ func (w *worker) start() {
if isTm {
err := tm.Init(w.chain, func(parent common.Hash, coinbase common.Address, timestamp uint64) (*types.Block, error) {
return w.getSealingBlock(parent, timestamp, coinbase, common.Hash{})
})
}, w.mux)
if err != nil {
log.Crit("tm.Init", "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ var Web3QTestnetBootnodes = []string{

// TODO: to update
var Web3QGalileoBootnodes = []string{
"enode://1b9032f19ae39390e84718071ac8d560f5a11e1b8e02de4a40654a9d2950ae77b34a2ca90854413dfe5973c0040d0928a5cf27a46cd8cc1c6a8fbc1fb7d2825f@127.0.0.1:30303",
"enode://1284264b02b32fafd3448486926b372a225b35282a7e4175b57b5949ce1b3711e1b2db017156c19b3b9d141384fddf73dbf44746d49be59213d6275dc04b7c4f@127.0.0.1:30303",
}

var Web3QMainnetBootnodes = []string{
Expand Down

0 comments on commit c5c965b

Please sign in to comment.