mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
[release-v1.4] rpcserver: update block template reconstruction.
This simplifies solved block reconstruction by removing the pkScript reassignment and regeneration of the merkle root.
This commit is contained in:
parent
10435f4de6
commit
63524cddcb
31
rpcserver.go
31
rpcserver.go
@ -4227,24 +4227,25 @@ func handleGetWorkSubmission(s *rpcServer, hexData string) (interface{}, error)
|
||||
}
|
||||
|
||||
// Reconstruct the block using the submitted header stored block info.
|
||||
// A temporary block is used because we will be mutating the contents
|
||||
// for the construction of the correct regular merkle tree. You must
|
||||
// also deep copy the block itself because it could be accessed outside
|
||||
// of the GW workstate mutexes once it gets submitted to the
|
||||
// The MsgBlock is copied here because it could be accessed
|
||||
// outside of the GW workstate mutexes once it gets submitted to the
|
||||
// blockchain.
|
||||
tempBlock := dcrutil.NewBlockDeepCopy(blockInfo.msgBlock)
|
||||
msgBlock := tempBlock.MsgBlock()
|
||||
msgBlock.Header = submittedHeader
|
||||
if msgBlock.Header.Height > 1 {
|
||||
pkScriptCopy := make([]byte, len(blockInfo.pkScript))
|
||||
copy(pkScriptCopy, blockInfo.pkScript)
|
||||
msgBlock.Transactions[0].TxOut[1].PkScript = blockInfo.pkScript
|
||||
merkles := blockchain.BuildMerkleTreeStore(tempBlock.Transactions())
|
||||
msgBlock.Header.MerkleRoot = *merkles[len(merkles)-1]
|
||||
|
||||
msgBlockB, err := blockInfo.msgBlock.Bytes()
|
||||
if err != nil {
|
||||
return false, rpcInternalError("Unexpected error "+
|
||||
"while serializing MsgBlock: "+err.Error(), "")
|
||||
}
|
||||
|
||||
// The real block to submit, with a proper nonce and extraNonce.
|
||||
block := dcrutil.NewBlockDeepCopyCoinbase(msgBlock)
|
||||
var msgBlock wire.MsgBlock
|
||||
err = msgBlock.FromBytes(msgBlockB)
|
||||
if err != nil {
|
||||
return false, rpcInternalError("Unexpected error "+
|
||||
"while creating MsgBlock from bytes: "+err.Error(), "")
|
||||
}
|
||||
|
||||
msgBlock.Header = submittedHeader
|
||||
block := dcrutil.NewBlock(&msgBlock)
|
||||
|
||||
// Ensure the submitted block hash is less than the target difficulty.
|
||||
err = blockchain.CheckProofOfWork(&block.MsgBlock().Header,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user