Merge branch 'master' into wb/issue-7950

This commit is contained in:
William Banfield
2022-04-06 22:20:44 -04:00
75 changed files with 1366 additions and 1190 deletions
+17 -8
View File
@@ -1,5 +1,5 @@
#! /bin/bash
set -ex
#!/bin/bash
set -exo pipefail
#- kvstore over socket, curl
@@ -8,9 +8,19 @@ set -ex
export PATH="$GOBIN:$PATH"
export TMHOME=$HOME/.tendermint_app
function kvstore_over_socket(){
rm -rf $TMHOME
function init_validator() {
rm -rf -- "$TMHOME"
tendermint init validator
# The default configuration sets a null indexer, but these tests require
# indexing to be enabled. Rewrite the config file to set the "kv" indexer
# before starting up the node.
sed -i'' -e '/indexer = \["null"\]/c\
indexer = ["kv"]' "$TMHOME/config/config.toml"
}
function kvstore_over_socket() {
init_validator
echo "Starting kvstore_over_socket"
abci-cli kvstore > /dev/null &
pid_kvstore=$!
@@ -25,9 +35,8 @@ function kvstore_over_socket(){
}
# start tendermint first
function kvstore_over_socket_reorder(){
rm -rf $TMHOME
tendermint init validator
function kvstore_over_socket_reorder() {
init_validator
echo "Starting kvstore_over_socket_reorder (ie. start tendermint first)"
tendermint start --mode validator > tendermint.log &
pid_tendermint=$!
@@ -42,7 +51,7 @@ function kvstore_over_socket_reorder(){
kill -9 $pid_kvstore $pid_tendermint
}
case "$1" in
case "$1" in
"kvstore_over_socket")
kvstore_over_socket
;;
+3
View File
@@ -1,2 +1,5 @@
[rpc]
laddr = "tcp://0.0.0.0:26657"
[tx-index]
indexer = ["kv"]
+13 -1
View File
@@ -306,7 +306,19 @@ func (app *Application) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) a
func (app *Application) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
// None of the transactions are modified by this application.
return abci.ResponsePrepareProposal{ModifiedTxStatus: abci.ResponsePrepareProposal_UNMODIFIED}
trs := make([]*abci.TxRecord, 0, len(req.Txs))
var totalBytes int64
for _, tx := range req.Txs {
totalBytes += int64(len(tx))
if totalBytes > req.MaxTxBytes {
break
}
trs = append(trs, &abci.TxRecord{
Action: abci.TxRecord_UNMODIFIED,
Tx: tx,
})
}
return abci.ResponsePrepareProposal{TxRecords: trs}
}
// ProcessProposal implements part of the Application interface.
+1 -1
View File
@@ -92,7 +92,7 @@ func (s *SnapshotStore) Create(state *State) (abci.Snapshot, error) {
snapshot := abci.Snapshot{
Height: state.Height,
Format: 1,
Hash: hashItems(state.Values),
Hash: hashItems(state.Values, state.Height),
Chunks: byteChunks(bz),
}
err = os.WriteFile(filepath.Join(s.dir, fmt.Sprintf("%v.json", state.Height)), bz, 0644)
+8 -4
View File
@@ -3,6 +3,7 @@ package app
import (
"crypto/sha256"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
@@ -38,7 +39,7 @@ func NewState(dir string, persistInterval uint64) (*State, error) {
previousFile: filepath.Join(dir, prevStateFileName),
persistInterval: persistInterval,
}
state.Hash = hashItems(state.Values)
state.Hash = hashItems(state.Values, state.Height)
err := state.load()
switch {
case errors.Is(err, os.ErrNotExist):
@@ -114,7 +115,7 @@ func (s *State) Import(height uint64, jsonBytes []byte) error {
}
s.Height = height
s.Values = values
s.Hash = hashItems(values)
s.Hash = hashItems(values, height)
return s.save()
}
@@ -140,7 +141,6 @@ func (s *State) Set(key, value string) {
func (s *State) Commit() (uint64, []byte, error) {
s.Lock()
defer s.Unlock()
s.Hash = hashItems(s.Values)
switch {
case s.Height > 0:
s.Height++
@@ -149,6 +149,7 @@ func (s *State) Commit() (uint64, []byte, error) {
default:
s.Height = 1
}
s.Hash = hashItems(s.Values, s.Height)
if s.persistInterval > 0 && s.Height%s.persistInterval == 0 {
err := s.save()
if err != nil {
@@ -171,7 +172,7 @@ func (s *State) Rollback() error {
}
// hashItems hashes a set of key/value items.
func hashItems(items map[string]string) []byte {
func hashItems(items map[string]string, height uint64) []byte {
keys := make([]string, 0, len(items))
for key := range items {
keys = append(keys, key)
@@ -179,6 +180,9 @@ func hashItems(items map[string]string) []byte {
sort.Strings(keys)
hasher := sha256.New()
var b [8]byte
binary.BigEndian.PutUint64(b[:], height)
_, _ = hasher.Write(b[:])
for _, key := range keys {
_, _ = hasher.Write([]byte(key))
_, _ = hasher.Write([]byte{0})
+1
View File
@@ -237,6 +237,7 @@ func MakeConfig(node *e2e.Node) (*config.Config, error) {
cfg := config.DefaultConfig()
cfg.Moniker = node.Name
cfg.ProxyApp = AppAddressTCP
cfg.TxIndex = config.TestTxIndexConfig()
if node.LogLevel != "" {
cfg.LogLevel = node.LogLevel
+14 -13
View File
@@ -48,23 +48,24 @@ func TestApp_Hash(t *testing.T) {
info, err := client.ABCIInfo(ctx)
require.NoError(t, err)
require.NotEmpty(t, info.Response.LastBlockAppHash, "expected app to return app hash")
// In next-block execution, the app hash is stored in the next block
blockHeight := info.Response.LastBlockHeight + 1
status, err := client.Status(ctx)
require.NoError(t, err)
require.NotZero(t, status.SyncInfo.LatestBlockHeight)
require.Eventually(t, func() bool {
status, err := client.Status(ctx)
require.NoError(t, err)
require.NotZero(t, status.SyncInfo.LatestBlockHeight)
return status.SyncInfo.LatestBlockHeight >= blockHeight
}, 60*time.Second, 500*time.Millisecond)
block, err := client.Block(ctx, &info.Response.LastBlockHeight)
block, err := client.Block(ctx, &blockHeight)
require.NoError(t, err)
if info.Response.LastBlockHeight == block.Block.Height {
require.Equal(t,
fmt.Sprintf("%x", info.Response.LastBlockAppHash),
fmt.Sprintf("%x", block.Block.AppHash.Bytes()),
"app hash does not match last block's app hash")
}
require.True(t, status.SyncInfo.LatestBlockHeight >= info.Response.LastBlockHeight,
"status out of sync with application")
require.Equal(t, blockHeight, block.Block.Height)
require.Equal(t,
fmt.Sprintf("%x", info.Response.LastBlockAppHash),
fmt.Sprintf("%x", block.Block.AppHash.Bytes()),
"app hash does not match last block's app hash")
})
}