-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
process blocks #5681
process blocks #5681
Changes from 1 commit
39845e1
f9f3449
cc1d38e
4b84c44
5f6fdb4
1247b72
f97dce9
c1355c0
8a5fa28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,13 +2,15 @@ package process | |||||
|
||||||
import ( | ||||||
"github.com/multiversx/mx-chain-core-go/data" | ||||||
"github.com/multiversx/mx-chain-go/node/chainSimulator/configs" | ||||||
) | ||||||
|
||||||
type blocksCreator struct { | ||||||
nodeHandler NodeHandler | ||||||
blsKeyBytes []byte | ||||||
} | ||||||
|
||||||
// NewBlocksCreator will create a new instance of blocksCreator | ||||||
func NewBlocksCreator(nodeHandler NodeHandler, blsKeyBytes []byte) (*blocksCreator, error) { | ||||||
return &blocksCreator{ | ||||||
nodeHandler: nodeHandler, | ||||||
|
@@ -19,18 +21,8 @@ func NewBlocksCreator(nodeHandler NodeHandler, blsKeyBytes []byte) (*blocksCreat | |||||
// CreateNewBlock create and process a new block | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing in the next PR |
||||||
func (creator *blocksCreator) CreateNewBlock() error { | ||||||
bp := creator.nodeHandler.GetProcessComponents().BlockProcessor() | ||||||
currentHeader := creator.nodeHandler.GetChainHandler().GetCurrentBlockHeader() | ||||||
var nonce, round uint64 | ||||||
var prevHash, prevRandSeed []byte | ||||||
if currentHeader != nil { | ||||||
nonce, round = currentHeader.GetNonce(), currentHeader.GetRound() | ||||||
prevHash = creator.nodeHandler.GetChainHandler().GetCurrentBlockHeaderHash() | ||||||
prevRandSeed = currentHeader.GetRandSeed() | ||||||
} else { | ||||||
prevHash = creator.nodeHandler.GetChainHandler().GetGenesisHeaderHash() | ||||||
prevRandSeed = creator.nodeHandler.GetChainHandler().GetGenesisHeader().GetRandSeed() | ||||||
} | ||||||
|
||||||
nonce, round, prevHash, prevRandSeed := creator.getPreviousHeaderData() | ||||||
newHeader, err := bp.CreateNewHeader(round+1, nonce+1) | ||||||
if err != nil { | ||||||
return err | ||||||
|
@@ -55,7 +47,7 @@ func (creator *blocksCreator) CreateNewBlock() error { | |||||
return err | ||||||
} | ||||||
|
||||||
err = newHeader.SetChainID([]byte("chain")) | ||||||
err = newHeader.SetChainID([]byte(configs.ChainID)) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
@@ -100,6 +92,21 @@ func (creator *blocksCreator) CreateNewBlock() error { | |||||
return creator.nodeHandler.GetBroadcastMessenger().BroadcastBlockDataLeader(header, miniBlocks, transactions, creator.blsKeyBytes) | ||||||
} | ||||||
|
||||||
func (creator *blocksCreator) getPreviousHeaderData() (nonce, round uint64, prevHash, prevRandSeed []byte) { | ||||||
currentHeader := creator.nodeHandler.GetChainHandler().GetCurrentBlockHeader() | ||||||
|
||||||
if currentHeader != nil { | ||||||
nonce, round = currentHeader.GetNonce(), currentHeader.GetRound() | ||||||
prevHash = creator.nodeHandler.GetChainHandler().GetCurrentBlockHeaderHash() | ||||||
prevRandSeed = currentHeader.GetRandSeed() | ||||||
} else { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could have omitted the "else" branch and return on L101 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||||||
prevHash = creator.nodeHandler.GetChainHandler().GetGenesisHeaderHash() | ||||||
prevRandSeed = creator.nodeHandler.GetChainHandler().GetGenesisHeader().GetRandSeed() | ||||||
} | ||||||
|
||||||
return | ||||||
} | ||||||
|
||||||
func (creator *blocksCreator) setHeaderSignatures(header data.HeaderHandler) error { | ||||||
signingHandler := creator.nodeHandler.GetCryptoComponents().ConsensusSigningHandler() | ||||||
headerClone := header.ShallowClone() | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added