Browse Source

state: revert event hashing (#5159)

See ADR 058

Closes #5113

Spec PR: https://github.com/tendermint/spec/pull/122
pull/5173/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
4d43bfe3bd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 40 deletions
  1. +1
    -1
      CHANGELOG_PENDING.md
  2. +8
    -4
      Vagrantfile
  3. +3
    -26
      state/store.go
  4. +7
    -8
      state/store_test.go
  5. +0
    -1
      types/results.go

+ 1
- 1
CHANGELOG_PENDING.md View File

@ -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) - [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). - Add `max_num` to consensus evidence parameters (default: 50 items).
- [evidence] \#4725 Remove `Pubkey` from `DuplicateVoteEvidence` - [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) - [types] [\#4792](https://github.com/tendermint/tendermint/pull/4792) Sort validators by voting power to enable faster commit verification (@melekes)
- On-disk serialization - On-disk serialization


+ 8
- 4
Vagrantfile View File

@ -2,7 +2,7 @@
# vi: set ft=ruby : # vi: set ft=ruby :
Vagrant.configure("2") do |config| Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |v| config.vm.provider "virtualbox" do |v|
v.memory = 4096 v.memory = 4096
@ -19,20 +19,24 @@ Vagrant.configure("2") do |config|
# install docker # install docker
apt-get install -y --no-install-recommends apt-transport-https \ 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 - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository \ add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \ $(lsb_release -cs) \
stable" stable"
apt-get update
apt-get install -y docker-ce apt-get install -y docker-ce
usermod -a -G docker vagrant
usermod -aG docker vagrant
# install go # install go
wget -q https://dl.google.com/go/go1.14.linux-amd64.tar.gz wget -q https://dl.google.com/go/go1.14.linux-amd64.tar.gz
tar -xvf go1.14.linux-amd64.tar.gz tar -xvf go1.14.linux-amd64.tar.gz
mv go /usr/local mv go /usr/local
rm -f go1.13.linux-amd64.tar.gz
rm -f go1.14.linux-amd64.tar.gz
# install nodejs (for docs) # install nodejs (for docs)
curl -sL https://deb.nodesource.com/setup_11.x | bash - curl -sL https://deb.nodesource.com/setup_11.x | bash -


+ 3
- 26
state/store.go View File

@ -7,7 +7,6 @@ import (
dbm "github.com/tendermint/tm-db" dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types" abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/merkle"
tmmath "github.com/tendermint/tendermint/libs/math" tmmath "github.com/tendermint/tendermint/libs/math"
tmos "github.com/tendermint/tendermint/libs/os" tmos "github.com/tendermint/tendermint/libs/os"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state" 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 // See merkle.SimpleHashFromByteSlices
func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte { 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 // LoadABCIResponses loads the ABCIResponses for the given height from the


+ 7
- 8
state/store_test.go View File

@ -5,7 +5,6 @@ import (
"os" "os"
"testing" "testing"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
@ -15,7 +14,6 @@ import (
cfg "github.com/tendermint/tendermint/config" cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/merkle"
tmrand "github.com/tendermint/tendermint/libs/rand" tmrand "github.com/tendermint/tendermint/libs/rand"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state" tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
@ -201,14 +199,15 @@ func TestABCIResponsesResultsHash(t *testing.T) {
root := sm.ABCIResponsesResultsHash(responses) root := sm.ABCIResponsesResultsHash(responses)
bbeBytes, _ := proto.Marshal(responses.BeginBlock)
// root should be Merkle tree root of DeliverTxs responses
results := types.NewResults(responses.DeliverTxs) 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 { func sliceToMap(s []int64) map[int64]bool {


+ 0
- 1
types/results.go View File

@ -50,6 +50,5 @@ func deterministicResponseDeliverTx(response *abci.ResponseDeliverTx) *abci.Resp
Data: response.Data, Data: response.Data,
GasWanted: response.GasWanted, GasWanted: response.GasWanted,
GasUsed: response.GasUsed, GasUsed: response.GasUsed,
Events: response.Events,
} }
} }

Loading…
Cancel
Save