-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
C:consensusComponent: ConsensusComponent: ConsensusC:mempoolComponent: MempoolComponent: MempoolT:bugType Bug (Confirmed)Type Bug (Confirmed)T:securityType: Security (specify priority)Type: Security (specify priority)
Description
I wrote a test for amino overhead of tx:
func TestAmino(t *testing.T) {
txs := []types.Tx{
[]byte{1, 2, 3},
[]byte{1, 2, 3},
}
var totalBytes int64 = 0
for _, tx := range txs {
aminoOverhead := int64(amino.UvarintSize(uint64(len(tx))))
totalBytes += aminoOverhead + int64(len(tx))
}
bz, _ := cdc.MarshalBinary(txs)
println("len: ", len(txs), "\nexpected length: ", totalBytes, "\nactual length: ", len(bz), "\ndiff: ", (int64(len(bz)) - totalBytes))
}
/*
=== RUN TestAmino
len: 2
expected length: 8
actual length: 11
diff: 3
--- PASS: TestAmino (0.00s)
PASS
*/The underlying reason is amino.UvarintSize forget encodeFieldNumberAndTyp3 which will be called in marshal list slice. So we add one extra byte in every tx when marshaling real txs and that's why we have a diff in the test.
It will cause consensus failure because the actual block size exceeds the max block size for the error deciding amino overhead of txs.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C:consensusComponent: ConsensusComponent: ConsensusC:mempoolComponent: MempoolComponent: MempoolT:bugType Bug (Confirmed)Type Bug (Confirmed)T:securityType: Security (specify priority)Type: Security (specify priority)