mirror of
https://github.com/tendermint/tendermint.git
synced 2025-12-23 06:15:19 +00:00
state: revert event hashing (#5159)
See ADR 058 Closes #5113 Spec PR: https://github.com/tendermint/spec/pull/122
This commit is contained in:
@@ -36,7 +36,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
|
||||
- [evidence] [\#4780](https://github.com/tendermint/tendermint/pull/4780) Cap evidence to an absolute number (@cmwaters)
|
||||
- Add `max_num` to consensus evidence parameters (default: 50 items).
|
||||
- [evidence] \#4725 Remove `Pubkey` from `DuplicateVoteEvidence`
|
||||
- [state] \#4845 Include `BeginBlock#Events`, `EndBlock#Events`, `DeliverTx#Events`, `GasWanted` and `GasUsed` into `LastResultsHash` (@melekes)
|
||||
- [state] \#4845 Include `GasWanted` and `GasUsed` into `LastResultsHash` (@melekes)
|
||||
- [types] [\#4792](https://github.com/tendermint/tendermint/pull/4792) Sort validators by voting power to enable faster commit verification (@melekes)
|
||||
|
||||
- On-disk serialization
|
||||
|
||||
12
Vagrantfile
vendored
12
Vagrantfile
vendored
@@ -2,7 +2,7 @@
|
||||
# vi: set ft=ruby :
|
||||
|
||||
Vagrant.configure("2") do |config|
|
||||
config.vm.box = "ubuntu/xenial64"
|
||||
config.vm.box = "ubuntu/focal64"
|
||||
|
||||
config.vm.provider "virtualbox" do |v|
|
||||
v.memory = 4096
|
||||
@@ -19,20 +19,24 @@ Vagrant.configure("2") do |config|
|
||||
|
||||
# install docker
|
||||
apt-get install -y --no-install-recommends apt-transport-https \
|
||||
ca-certificates curl software-properties-common
|
||||
ca-certificates \
|
||||
curl \
|
||||
gnupg-agent \
|
||||
software-properties-common
|
||||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
|
||||
add-apt-repository \
|
||||
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
|
||||
$(lsb_release -cs) \
|
||||
stable"
|
||||
apt-get update
|
||||
apt-get install -y docker-ce
|
||||
usermod -a -G docker vagrant
|
||||
usermod -aG docker vagrant
|
||||
|
||||
# install go
|
||||
wget -q https://dl.google.com/go/go1.14.linux-amd64.tar.gz
|
||||
tar -xvf go1.14.linux-amd64.tar.gz
|
||||
mv go /usr/local
|
||||
rm -f go1.13.linux-amd64.tar.gz
|
||||
rm -f go1.14.linux-amd64.tar.gz
|
||||
|
||||
# install nodejs (for docs)
|
||||
curl -sL https://deb.nodesource.com/setup_11.x | bash -
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
tmmath "github.com/tendermint/tendermint/libs/math"
|
||||
tmos "github.com/tendermint/tendermint/libs/os"
|
||||
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
|
||||
@@ -269,34 +268,12 @@ func PruneStates(db dbm.DB, from int64, to int64) error {
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
// ABCIResponsesResultsHash returns the root hash of a Merkle tree with 3 leafs:
|
||||
// 1) proto encoded ResponseBeginBlock.Events
|
||||
// 2) root hash of a Merkle tree of ResponseDeliverTx responses (see ABCIResults.Hash)
|
||||
// 3) proto encoded ResponseEndBlock.Events
|
||||
// ABCIResponsesResultsHash returns the root hash of a Merkle tree of
|
||||
// ResponseDeliverTx responses (see ABCIResults.Hash)
|
||||
//
|
||||
// See merkle.SimpleHashFromByteSlices
|
||||
func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte {
|
||||
// proto-encode BeginBlock events.
|
||||
bbeBytes, err := proto.Marshal(&abci.ResponseBeginBlock{
|
||||
Events: ar.BeginBlock.Events,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Build a Merkle tree of proto-encoded DeliverTx results and get a hash.
|
||||
results := types.NewResults(ar.DeliverTxs)
|
||||
|
||||
// proto-encode EndBlock events.
|
||||
ebeBytes, err := proto.Marshal(&abci.ResponseEndBlock{
|
||||
Events: ar.EndBlock.Events,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Build a Merkle tree out of the above 3 binary slices.
|
||||
return merkle.HashFromByteSlices([][]byte{bbeBytes, results.Hash(), ebeBytes})
|
||||
return types.NewResults(ar.DeliverTxs).Hash()
|
||||
}
|
||||
|
||||
// LoadABCIResponses loads the ABCIResponses for the given height from the
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
@@ -15,7 +14,6 @@ import (
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
"github.com/tendermint/tendermint/crypto/merkle"
|
||||
tmrand "github.com/tendermint/tendermint/libs/rand"
|
||||
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
@@ -201,14 +199,15 @@ func TestABCIResponsesResultsHash(t *testing.T) {
|
||||
|
||||
root := sm.ABCIResponsesResultsHash(responses)
|
||||
|
||||
bbeBytes, _ := proto.Marshal(responses.BeginBlock)
|
||||
// root should be Merkle tree root of DeliverTxs responses
|
||||
results := types.NewResults(responses.DeliverTxs)
|
||||
ebeBytes, _ := proto.Marshal(responses.EndBlock)
|
||||
assert.Equal(t, root, results.Hash())
|
||||
|
||||
root2, proofs := merkle.ProofsFromByteSlices([][]byte{bbeBytes, results.Hash(), ebeBytes})
|
||||
|
||||
assert.Equal(t, root2, root)
|
||||
assert.NoError(t, proofs[1].Verify(root, results.Hash()))
|
||||
// test we can prove first DeliverTx
|
||||
proof := results.ProveResult(0)
|
||||
bz, err := results[0].Marshal()
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, proof.Verify(root, bz))
|
||||
}
|
||||
|
||||
func sliceToMap(s []int64) map[int64]bool {
|
||||
|
||||
@@ -50,6 +50,5 @@ func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.Resp
|
||||
Data: response.Data,
|
||||
GasWanted: response.GasWanted,
|
||||
GasUsed: response.GasUsed,
|
||||
Events: response.Events,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user