Skip to content

Commit

Permalink
Set ChainID in ABCI Header (cosmos#185)
Browse files Browse the repository at this point in the history
Fixes cosmos#184.
  • Loading branch information
tzdybal authored Nov 18, 2021
1 parent 08d9cd2 commit d974251
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewManager(
return nil, err
}

exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, mempool, proxyApp, logger)
exec := state.NewBlockExecutor(proposerAddress, conf.NamespaceID, genesis.ChainID, mempool, proxyApp, logger)
if s.LastBlockHeight+1 == genesis.InitialHeight {
res, err := exec.InitChain(genesis)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions conv/abci/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import (
)

// ToABCIHeader converts Optimint header to Header format defined in ABCI.
// Caller should fill all the fields that are not available in Optimint header (like ChainID).
func ToABCIHeader(header *types.Header) (tmproto.Header, error) {
hash := header.Hash()
return tmproto.Header{
Version: tmversion.Consensus{
Block: uint64(header.Version.Block),
App: uint64(header.Version.App),
Block: header.Version.Block,
App: header.Version.App,
},
ChainID: "", // TODO(tzdybal)
Height: int64(header.Height),
Time: time.Unix(int64(header.Time), 0),
Height: int64(header.Height),
Time: time.Unix(int64(header.Time), 0),
LastBlockId: tmproto.BlockID{
Hash: hash[:],
PartSetHeader: tmproto.PartSetHeader{
Expand Down
2 changes: 1 addition & 1 deletion node/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestAggregatorMode(t *testing.T) {
}
}
}()
time.Sleep(5 * time.Second)
time.Sleep(3 * time.Second)
cancel()
}

Expand Down
4 changes: 3 additions & 1 deletion state/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
type BlockExecutor struct {
proposerAddress []byte
namespaceID [8]byte
chainID string
proxyApp proxy.AppConnConsensus
mempool mempool.Mempool

Expand All @@ -30,7 +31,7 @@ type BlockExecutor struct {

// NewBlockExecutor creates new instance of BlockExecutor.
// Proposer address and namespace ID will be used in all newly created blocks.
func NewBlockExecutor(proposerAddress []byte, namespaceID [8]byte, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, logger log.Logger) *BlockExecutor {
func NewBlockExecutor(proposerAddress []byte, namespaceID [8]byte, chainID string, mempool mempool.Mempool, proxyApp proxy.AppConnConsensus, logger log.Logger) *BlockExecutor {
return &BlockExecutor{
proposerAddress: proposerAddress,
namespaceID: namespaceID,
Expand Down Expand Up @@ -226,6 +227,7 @@ func (e *BlockExecutor) execute(ctx context.Context, state State, block *types.B

hash := block.Hash()
abciHeader, err := abciconv.ToABCIHeader(&block.Header)
abciHeader.ChainID = e.chainID
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions state/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestCreateBlock(t *testing.T) {
nsID := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}

mpool := mempool.NewCListMempool(cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client), 0)
executor := NewBlockExecutor([]byte("test address"), nsID, mpool, proxy.NewAppConnConsensus(client), logger)
executor := NewBlockExecutor([]byte("test address"), nsID, "test", mpool, proxy.NewAppConnConsensus(client), logger)

state := State{}
state.ConsensusParams.Block.MaxBytes = 100
Expand Down Expand Up @@ -88,9 +88,10 @@ func TestApplyBlock(t *testing.T) {
require.NotNil(client)

nsID := [8]byte{1, 2, 3, 4, 5, 6, 7, 8}
chainID := "test"

mpool := mempool.NewCListMempool(cfg.DefaultMempoolConfig(), proxy.NewAppConnMempool(client), 0)
executor := NewBlockExecutor([]byte("test address"), nsID, mpool, proxy.NewAppConnConsensus(client), logger)
executor := NewBlockExecutor([]byte("test address"), nsID, chainID, mpool, proxy.NewAppConnConsensus(client), logger)

state := State{}
state.InitialHeight = 1
Expand Down

0 comments on commit d974251

Please sign in to comment.