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

@ -57,6 +57,8 @@ func TestRecoveryMessage_Setters(t *testing.T) {
ps := r.GetPrepareResponses(p, pubs)
require.Len(t, ps, 1)
// Update hashes and serialized data.
_ = ps[0].Hash()
require.Equal(t, p2, ps[0])
ps0 := ps[0].(*Payload)
require.True(t, srv.validatePayload(ps0))
@ -91,6 +93,8 @@ func TestRecoveryMessage_Setters(t *testing.T) {
ps := r.GetChangeViews(p, pubs)
require.Len(t, ps, 1)
// update hashes and serialized data.
_ = ps[0].Hash()
require.Equal(t, p3, ps[0])
ps0 := ps[0].(*Payload)
@ -109,6 +113,8 @@ func TestRecoveryMessage_Setters(t *testing.T) {
ps := r.GetCommits(p, pubs)
require.Len(t, ps, 1)
// update hashes and serialized data.
_ = ps[0].Hash()
require.Equal(t, p4, ps[0])
ps0 := ps[0].(*Payload)