Store group sigs in the real header, not in a copy

(*Block) Header() returns a (shallow) copy of the header, where we were
storing group signatures and signer bitmaps.  This had no effect, and
the on-chain block was still missing these signatures.
pull/628/head
Eugene Kim 6 years ago
parent a7967c2f74
commit 9fc97e43b0
  1. 10
      consensus/consensus_leader.go
  2. 10
      consensus/consensus_validator.go
  3. 24
      core/types/block.go

@ -308,10 +308,12 @@ func (consensus *Consensus) processCommitMessage(message *msg_pb.Message) {
} }
// Sign the block // Sign the block
copy(blockObj.Header().PrepareSignature[:], consensus.aggregatedPrepareSig.Serialize()[:]) blockObj.SetPrepareSig(
copy(blockObj.Header().PrepareBitmap[:], consensus.prepareBitmap.Bitmap) consensus.aggregatedPrepareSig.Serialize(),
copy(blockObj.Header().CommitSignature[:], consensus.aggregatedCommitSig.Serialize()[:]) consensus.prepareBitmap.Bitmap)
copy(blockObj.Header().CommitBitmap[:], consensus.commitBitmap.Bitmap) blockObj.SetCommitSig(
consensus.aggregatedCommitSig.Serialize(),
consensus.commitBitmap.Bitmap)
consensus.state = targetState consensus.state = targetState

@ -282,10 +282,12 @@ func (consensus *Consensus) processCommittedMessage(message *msg_pb.Message) {
} }
// Put the signatures into the block // Put the signatures into the block
copy(blockObj.Header().PrepareSignature[:], consensus.aggregatedPrepareSig.Serialize()[:]) blockObj.SetPrepareSig(
copy(blockObj.Header().PrepareBitmap[:], consensus.prepareBitmap.Bitmap) consensus.aggregatedPrepareSig.Serialize(),
copy(blockObj.Header().CommitSignature[:], consensus.aggregatedCommitSig.Serialize()[:]) consensus.prepareBitmap.Bitmap)
copy(blockObj.Header().CommitBitmap[:], consensus.commitBitmap.Bitmap) blockObj.SetCommitSig(
consensus.aggregatedCommitSig.Serialize(),
consensus.commitBitmap.Bitmap)
utils.GetLogInstance().Info("Adding block to chain", "numTx", len(blockObj.Transactions())) utils.GetLogInstance().Info("Adding block to chain", "numTx", len(blockObj.Transactions()))
consensus.OnConsensusDone(&blockObj) consensus.OnConsensusDone(&blockObj)
consensus.ResetState() consensus.ResetState()

@ -30,6 +30,8 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"github.com/harmony-one/harmony/internal/utils"
) )
// Constants for block. // Constants for block.
@ -159,6 +161,28 @@ type Block struct {
ReceivedFrom interface{} ReceivedFrom interface{}
} }
// SetPrepareSig sets the block's prepare group signature.
func (b *Block) SetPrepareSig(sig []byte, signers []byte) {
if len(sig) != len(b.header.PrepareSignature) {
utils.GetLogInstance().Warn("SetPrepareSig: sig size mismatch",
"srcLen", len(sig),
"dstLen", len(b.header.PrepareSignature))
}
copy(b.header.PrepareSignature[:], sig[:])
b.header.PrepareBitmap = append(signers[:0:0], signers...)
}
// SetCommitSig sets the block's commit group signature.
func (b *Block) SetCommitSig(sig []byte, signers []byte) {
if len(sig) != len(b.header.CommitSignature) {
utils.GetLogInstance().Warn("SetCommitSig: sig size mismatch",
"srcLen", len(sig),
"dstLen", len(b.header.CommitSignature))
}
copy(b.header.CommitSignature[:], sig[:])
b.header.CommitBitmap = append(signers[:0:0], signers...)
}
// DeprecatedTd is an old relic for extracting the TD of a block. It is in the // DeprecatedTd is an old relic for extracting the TD of a block. It is in the
// code solely to facilitate upgrading the database from the old format to the // code solely to facilitate upgrading the database from the old format to the
// new, after which it should be deleted. Do not use! // new, after which it should be deleted. Do not use!

Loading…
Cancel
Save