Merge pull request #1086 from nspcc-dev/fix/recovery

consensus: fix commitCompact payload
This commit is contained in:
Roman Khimov 2020-06-22 14:52:15 +03:00 committed by GitHub
commit 9767817ee4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -228,6 +228,7 @@ func randomMessage(t *testing.T, mt messageType) io.Serializable {
case commitType:
var c commit
random.Fill(c.signature[:])
random.Fill(c.stateSig[:])
return &c
case recoveryRequestType:
return &recoveryRequest{timestamp: rand.Uint32()}
@ -275,12 +276,14 @@ func randomRecoveryMessage(t *testing.T) *recoveryMessage {
ViewNumber: 0,
ValidatorIndex: 1,
Signature: [64]byte{1, 2, 3},
StateSignature: [64]byte{4, 5, 6},
InvocationScript: random.Bytes(20),
},
{
ViewNumber: 0,
ValidatorIndex: 2,
Signature: [64]byte{11, 3, 4, 98},
StateSignature: [64]byte{4, 8, 15, 16, 23, 42},
InvocationScript: random.Bytes(10),
},
},

View file

@ -29,6 +29,7 @@ type (
ViewNumber byte
ValidatorIndex uint16
Signature [signatureSize]byte
StateSignature [signatureSize]byte
InvocationScript []byte
}
@ -112,6 +113,7 @@ func (p *commitCompact) DecodeBinary(r *io.BinReader) {
p.ViewNumber = r.ReadB()
p.ValidatorIndex = r.ReadU16LE()
r.ReadBytes(p.Signature[:])
r.ReadBytes(p.StateSignature[:])
p.InvocationScript = r.ReadVarBytes()
}
@ -120,6 +122,7 @@ func (p *commitCompact) EncodeBinary(w *io.BinWriter) {
w.WriteB(p.ViewNumber)
w.WriteU16LE(p.ValidatorIndex)
w.WriteBytes(p.Signature[:])
w.WriteBytes(p.StateSignature[:])
w.WriteVarBytes(p.InvocationScript)
}
@ -172,6 +175,7 @@ func (m *recoveryMessage) AddPayload(p payload.ConsensusPayload) {
ValidatorIndex: p.ValidatorIndex(),
ViewNumber: p.ViewNumber(),
Signature: p.GetCommit().(*commit).signature,
StateSignature: p.GetCommit().(*commit).stateSig,
InvocationScript: p.(*Payload).Witness.InvocationScript,
})
}
@ -250,7 +254,7 @@ func (m *recoveryMessage) GetCommits(p payload.ConsensusPayload, validators []cr
ps := make([]payload.ConsensusPayload, len(m.commitPayloads))
for i, c := range m.commitPayloads {
cc := fromPayload(commitType, p.(*Payload), &commit{signature: c.Signature})
cc := fromPayload(commitType, p.(*Payload), &commit{signature: c.Signature, stateSig: c.StateSignature})
cc.SetValidatorIndex(c.ValidatorIndex)
cc.Witness.InvocationScript = c.InvocationScript
cc.Witness.VerificationScript = getVerificationScript(c.ValidatorIndex, validators)