forked from TrueCloudLab/neoneo-go
consensus: check transactions count during PrepareRequest verification
This commit is contained in:
parent
23a3514cc0
commit
38103dcc7a
2 changed files with 14 additions and 3 deletions
|
@ -466,9 +466,10 @@ func (s *service) verifyBlock(b block.Block) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errInvalidPrevHash = errors.New("invalid PrevHash")
|
errInvalidPrevHash = errors.New("invalid PrevHash")
|
||||||
errInvalidVersion = errors.New("invalid Version")
|
errInvalidVersion = errors.New("invalid Version")
|
||||||
errInvalidStateRoot = errors.New("state root mismatch")
|
errInvalidStateRoot = errors.New("state root mismatch")
|
||||||
|
errInvalidTransactionsCount = errors.New("invalid transactions count")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
||||||
|
@ -487,6 +488,9 @@ func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
||||||
return fmt.Errorf("%w: %s != %s", errInvalidStateRoot, sr.Root, req.stateRoot)
|
return fmt.Errorf("%w: %s != %s", errInvalidStateRoot, sr.Root, req.stateRoot)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(req.TransactionHashes()) > int(s.ProtocolConfiguration.MaxTransactionsPerBlock) {
|
||||||
|
return fmt.Errorf("%w: max = %d, got %d", errInvalidTransactionsCount, s.ProtocolConfiguration.MaxTransactionsPerBlock, len(req.TransactionHashes()))
|
||||||
|
}
|
||||||
// Save lastProposal for getVerified().
|
// Save lastProposal for getVerified().
|
||||||
s.lastProposal = req.transactionHashes
|
s.lastProposal = req.transactionHashes
|
||||||
|
|
||||||
|
|
|
@ -323,6 +323,13 @@ func TestService_PrepareRequest(t *testing.T) {
|
||||||
|
|
||||||
sr, err := srv.Chain.GetStateModule().GetStateRoot(srv.dbft.BlockIndex - 1)
|
sr, err := srv.Chain.GetStateModule().GetStateRoot(srv.dbft.BlockIndex - 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
checkRequest(t, errInvalidTransactionsCount, &prepareRequest{stateRootEnabled: true,
|
||||||
|
prevHash: prevHash,
|
||||||
|
stateRoot: sr.Root,
|
||||||
|
transactionHashes: make([]util.Uint256, srv.ProtocolConfiguration.MaxTransactionsPerBlock+1),
|
||||||
|
})
|
||||||
|
|
||||||
checkRequest(t, nil, &prepareRequest{
|
checkRequest(t, nil, &prepareRequest{
|
||||||
stateRootEnabled: true,
|
stateRootEnabled: true,
|
||||||
prevHash: prevHash,
|
prevHash: prevHash,
|
||||||
|
|
Loading…
Reference in a new issue