crypto/consensus: sign hashes and cache them for consensus payloads

Avoid serializing payload again and again for various purposes. To sign it, we
only need a hash.

Some 2.4% gain in TPS could be achieved with this.
This commit is contained in:
Roman Khimov 2020-08-29 18:44:45 +03:00
parent 49e9c1aa0f
commit 53c014a0bb
11 changed files with 119 additions and 42 deletions

View file

@ -59,6 +59,13 @@ func (s *MPTRootBase) GetSignedPart() []byte {
return buf.Bytes()
}
// GetSignedHash returns hash of MPTRootBase which needs to be signed.
func (s *MPTRootBase) GetSignedHash() util.Uint256 {
buf := io.NewBufBinWriter()
s.EncodeBinary(buf.BinWriter)
return hash.Sha256(buf.Bytes())
}
// Equals checks if s == other.
func (s *MPTRootBase) Equals(other *MPTRootBase) bool {
return s.Version == other.Version && s.Index == other.Index &&