Skip to content
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

Reject out of date blocks submitted via RPC #1914

Merged
merged 7 commits into from
Dec 29, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions app/rpc/rpchandlers/submit_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request ap
}, nil
}

if !context.Config.AllowSubmittingNonDAABlocks {
virtualDAAScore, err := context.Domain.Consensus().GetVirtualDAAScore()
if err != nil {
return nil, err
}
// A simple heuristic check which signals that the mined block is out of date
// and should not be accepted unless user explicitly requests
daaWindowSize := uint64(context.Config.NetParams().DifficultyAdjustmentWindowSize)
if virtualDAAScore > daaWindowSize && domainBlock.Header.DAAScore() < virtualDAAScore-daaWindowSize {
return &appmessage.SubmitBlockResponseMessage{
Error: appmessage.RPCErrorf("Block rejected. Reason: block DAA score %d is too far "+
"behind virtual's DAA score %d", domainBlock.Header.DAAScore(), virtualDAAScore),
RejectReason: appmessage.RejectReasonBlockInvalid,
}, nil
}
}

err = context.ProtocolManager.AddBlock(domainBlock)
if err != nil {
isProtocolOrRuleError := errors.As(err, &ruleerrors.RuleError{}) || errors.As(err, &protocolerrors.ProtocolError{})
Expand Down
1 change: 1 addition & 0 deletions infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ type Flags struct {
IsArchivalNode bool `long:"archival" description:"Run as an archival node: don't delete old block data when moving the pruning point (Warning: heavy disk usage)'"`
AllowSubmitBlockWhenNotSynced bool `long:"allow-submit-block-when-not-synced" hidden:"true" description:"Allow the node to accept blocks from RPC while not synced (this flag is mainly used for testing)"`
EnableSanityCheckPruningUTXOSet bool `long:"enable-sanity-check-pruning-utxo" hidden:"true" description:"When moving the pruning point - check that the utxo set matches the utxo commitment"`
AllowSubmittingNonDAABlocks bool `long:"allow-non-daa-blocks" hidden:"false" description:"When submitting blocks via RPC - accept blocks which are out of virtual daa window (although such blocks are not rewarded anyhow)"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@someone235 is hidden:"false" needed here ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to move this flag directly to the submitBlock RPC command

NetworkFlags
ServiceOptions *ServiceOptions
}
Expand Down