forked from TrueCloudLab/neoneo-go
consensus: build MerkleRoot from hashes on block creation
Use transaction hashes for merkle root calculation as transactions itself can not yet be available.
This commit is contained in:
parent
3e3781168d
commit
8407031605
1 changed files with 11 additions and 1 deletions
|
@ -13,6 +13,7 @@ import (
|
|||
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||
|
@ -478,6 +479,15 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
|
|||
primaryIndex := uint32(ctx.PrimaryIndex)
|
||||
block.Block.ConsensusData.PrimaryIndex = primaryIndex
|
||||
|
||||
block.Block.RebuildMerkleRoot()
|
||||
hashes := make([]util.Uint256, len(ctx.TransactionHashes)+1)
|
||||
hashes[0] = block.Block.ConsensusData.Hash()
|
||||
copy(hashes[1:], ctx.TransactionHashes)
|
||||
mt, err := hash.NewMerkleTree(hashes)
|
||||
if err != nil {
|
||||
s.log.Fatal("can't calculate merkle root for the new block")
|
||||
return nil
|
||||
}
|
||||
block.Block.MerkleRoot = mt.Root()
|
||||
|
||||
return block
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue