Fix stability test mining (allow submission of non DAA blocks too) (#1917)

* Fix stability test mining (allow submission of non DAA blocks too)

* Comments for go fmt

* Use SubmitBlockAlsoIfNonDAA for all tests

Co-authored-by: Elichai Turkel <elichai.turkel@gmail.com>
This commit is contained in:
Michael Sutton 2021-12-30 11:04:56 +02:00 committed by GitHub
parent 504ec36612
commit 0e1d247915
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 14 deletions

View File

@ -14,9 +14,10 @@ func (msg *SubmitBlockRequestMessage) Command() MessageCommand {
}
// NewSubmitBlockRequestMessage returns a instance of the message
func NewSubmitBlockRequestMessage(block *RPCBlock) *SubmitBlockRequestMessage {
func NewSubmitBlockRequestMessage(block *RPCBlock, allowNonDAABlocks bool) *SubmitBlockRequestMessage {
return &SubmitBlockRequestMessage{
Block: block,
Block: block,
AllowNonDAABlocks: allowNonDAABlocks,
}
}

View File

@ -15,6 +15,7 @@ func (x *KaspadMessage_SubmitBlockRequest) toAppMessage() (appmessage.Message, e
func (x *KaspadMessage_SubmitBlockRequest) fromAppMessage(message *appmessage.SubmitBlockRequestMessage) error {
x.SubmitBlockRequest = &SubmitBlockRequestMessage{Block: &RpcBlock{}}
x.SubmitBlockRequest.AllowNonDAABlocks = message.AllowNonDAABlocks
return x.SubmitBlockRequest.Block.fromAppMessage(message.Block)
}

View File

@ -5,10 +5,9 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
)
// SubmitBlock sends an RPC request respective to the function's name and returns the RPC server's response
func (c *RPCClient) SubmitBlock(block *externalapi.DomainBlock) (appmessage.RejectReason, error) {
func (c *RPCClient) submitBlock(block *externalapi.DomainBlock, allowNonDAABlocks bool) (appmessage.RejectReason, error) {
err := c.rpcRouter.outgoingRoute().Enqueue(
appmessage.NewSubmitBlockRequestMessage(appmessage.DomainBlockToRPCBlock(block)))
appmessage.NewSubmitBlockRequestMessage(appmessage.DomainBlockToRPCBlock(block), allowNonDAABlocks))
if err != nil {
return appmessage.RejectReasonNone, err
}
@ -22,3 +21,13 @@ func (c *RPCClient) SubmitBlock(block *externalapi.DomainBlock) (appmessage.Reje
}
return appmessage.RejectReasonNone, nil
}
// SubmitBlock sends an RPC request respective to the function's name and returns the RPC server's response
func (c *RPCClient) SubmitBlock(block *externalapi.DomainBlock) (appmessage.RejectReason, error) {
return c.submitBlock(block, false)
}
// SubmitBlockAlsoIfNonDAA operates the same as SubmitBlock with the exception that `allowNonDAABlocks` is set to true
func (c *RPCClient) SubmitBlockAlsoIfNonDAA(block *externalapi.DomainBlock) (appmessage.RejectReason, error) {
return c.submitBlock(block, true)
}

View File

@ -75,7 +75,7 @@ func mineBlocks(consensusConfig *consensus.Config, rpcClient *rpc.Client, blockC
}
beforeSubmitBlockTime := time.Now()
rejectReason, err := rpcClient.SubmitBlock(block)
rejectReason, err := rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
return errors.Wrap(err, "error in SubmitBlock")
}

View File

@ -297,7 +297,7 @@ func logMinedBlockStatsAndUpdateStatFields(t *testing.T, rpcClient *rpcclient.RP
}
func submitMinedBlock(t *testing.T, rpcClient *rpcclient.RPCClient, block *externalapi.DomainBlock) {
_, err := rpcClient.SubmitBlock(block)
_, err := rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
t.Fatalf("SubmitBlock: %s", err)
}

View File

@ -77,7 +77,7 @@ func realMain() error {
mutableHeader.SetTimeInMilliseconds(genesisTimestamp + 1000)
block.Header = mutableHeader.ToImmutable()
mining.SolveBlock(block, rand.New(rand.NewSource(time.Now().UnixNano())))
_, err = rpcClient.SubmitBlock(block)
_, err = rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
return err
}
@ -183,7 +183,7 @@ func mineBlock(rpcClient *rpc.Client, miningAddress util.Address) error {
return err
}
mining.SolveBlock(block, rand.New(rand.NewSource(time.Now().UnixNano())))
_, err = rpcClient.SubmitBlock(block)
_, err = rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
return err
}
@ -202,7 +202,7 @@ func mineTips(numOfTips int, miningAddress util.Address, rpcClient *rpc.Client)
rd := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < numOfTips; i++ {
mining.SolveBlock(block, rd)
_, err = rpcClient.SubmitBlock(block)
_, err = rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
return err
}

View File

@ -107,7 +107,7 @@ func mineBlockAndGetCoinbaseTransaction(t *testing.T, rpcClient *rpcclient.RPCCl
t.Fatalf("RPCBlockToDomainBlock: %+v", err)
}
mine.SolveBlock(templateBlock)
_, err = rpcClient.SubmitBlock(templateBlock)
_, err = rpcClient.SubmitBlockAlsoIfNonDAA(templateBlock)
if err != nil {
t.Fatalf("SubmitBlock: %+v", err)
}

View File

@ -199,5 +199,5 @@ func mineOnTips(client *rpc.Client) (appmessage.RejectReason, error) {
mine.SolveBlock(domainBlock)
}
return client.SubmitBlock(domainBlock)
return client.SubmitBlockAlsoIfNonDAA(domainBlock)
}

View File

@ -228,7 +228,7 @@ func mineNextBlockWithMockTimestamps(t *testing.T, harness *appHarness, rd *rand
mining.SolveBlock(block, rd)
_, err = harness.rpcClient.SubmitBlock(block)
_, err = harness.rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
t.Fatalf("Error submitting block: %s", err)
}

View File

@ -24,7 +24,7 @@ func mineNextBlock(t *testing.T, harness *appHarness) *externalapi.DomainBlock {
rd := rand.New(rand.NewSource(time.Now().UnixNano()))
mining.SolveBlock(block, rd)
_, err = harness.rpcClient.SubmitBlock(block)
_, err = harness.rpcClient.SubmitBlockAlsoIfNonDAA(block)
if err != nil {
t.Fatalf("Error submitting block: %s", err)
}