mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
Reject out of date blocks submitted via RPC (#1914)
* Disallow by default RPC submission of out of date blocks (blocks which are out of virtual DAA window) * go fmt * Better condition test * Make allowNonDAABlocks an RPC field and not a command line flag * go fmt * one more go fmt
This commit is contained in:
parent
8282fb486e
commit
064b0454e8
@ -4,7 +4,8 @@ package appmessage
|
||||
// its respective RPC message
|
||||
type SubmitBlockRequestMessage struct {
|
||||
baseMessage
|
||||
Block *RPCBlock
|
||||
Block *RPCBlock
|
||||
AllowNonDAABlocks bool
|
||||
}
|
||||
|
||||
// Command returns the protocol command string for the message
|
||||
|
@ -34,6 +34,23 @@ func HandleSubmitBlock(context *rpccontext.Context, _ *router.Router, request ap
|
||||
}, nil
|
||||
}
|
||||
|
||||
if !submitBlockRequest.AllowNonDAABlocks {
|
||||
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{})
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -129,6 +129,7 @@ message GetCurrentNetworkResponseMessage{
|
||||
// See: GetBlockTemplateRequestMessage
|
||||
message SubmitBlockRequestMessage{
|
||||
RpcBlock block = 2;
|
||||
bool allowNonDAABlocks = 3;
|
||||
}
|
||||
|
||||
message SubmitBlockResponseMessage{
|
||||
|
@ -27,7 +27,8 @@ func (x *SubmitBlockRequestMessage) toAppMessage() (appmessage.Message, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &appmessage.SubmitBlockRequestMessage{
|
||||
Block: blockAppMessage,
|
||||
Block: blockAppMessage,
|
||||
AllowNonDAABlocks: x.GetAllowNonDAABlocks(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user