Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change list of Silei/v0.31.5 #5

Open
wants to merge 16 commits into
base: tendermint/v0.31.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions abci/types/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions abci/types/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,20 @@ message ResponseCheckTx {
string codespace = 8;
}

message TxEvent {
bytes address = 1;
bytes data = 2;
repeated bytes topics = 3;
uint64 block_number = 4;
bytes tx_hash = 5;
bytes block_hash = 6;
}

message ResponseDeliverTx {
uint32 code = 1;
bytes data = 2;
string log = 3; // nondeterministic
repeated TxEvent events = 9;
string info = 4; // nondeterministic
int64 gas_wanted = 5;
int64 gas_used = 6;
Expand Down
10 changes: 10 additions & 0 deletions abci/types/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"bytes"
"sort"
common "github.com/tendermint/tendermint/libs/common"
)

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -32,3 +33,12 @@ func (v ValidatorUpdates) Swap(i, j int) {
v[i] = v[j]
v[j] = v1
}

func GetTagByKey(tags []common.KVPair, key string) (common.KVPair, bool) {
for _, tag := range tags {
if bytes.Equal(tag.Key, []byte(key)) {
return tag, true
}
}
return common.KVPair{}, false
}
14 changes: 14 additions & 0 deletions blockchain/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ func (bs *BlockStore) SaveBlock(block *types.Block, blockParts *types.PartSet, s
bs.db.SetSync(nil, nil)
}

func (bs *BlockStore) RetreatLastBlock() {
height := bs.height
bs.db.Delete(calcBlockMetaKey(height))
bs.db.Delete(calcBlockCommitKey(height-1))
bs.db.Delete(calcSeenCommitKey(height))
BlockStoreStateJSON{Height: height-1 }.Save(bs.db)
// Done!
bs.mtx.Lock()
bs.height = height
bs.mtx.Unlock()
// Flush
bs.db.SetSync(nil, nil)
}

func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) {
if height != bs.Height()+1 {
cmn.PanicSanity(fmt.Sprintf("BlockStore can only save contiguous blocks. Wanted %v, got %v", bs.Height()+1, height))
Expand Down
3 changes: 3 additions & 0 deletions cmd/tendermint/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ func AddNodeFlags(cmd *cobra.Command) {

// node flags
cmd.Flags().Bool("fast_sync", config.FastSync, "Fast blockchain syncing")
cmd.Flags().Bool("deprecated", config.Deprecated, "Mark blockchain as deprecated")
cmd.Flags().Int64("replay_height", config.ReplayHeight, "Specify which height to replay to, this is useful for exporting at any height")


// abci flags
cmd.Flags().String("proxy_app", config.ProxyApp, "Proxy app address, or one of: 'kvstore', 'persistent_kvstore', 'counter', 'counter_serial' or 'noop' for local testing.")
Expand Down
13 changes: 11 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ type BaseConfig struct {
// and verifying their commits
FastSync bool `mapstructure:"fast_sync"`

// If the blockchain is deprecated, run node with Deprecated will
// work in query only mode. Consensus engine and p2p gossip will be
// shutdown
Deprecated bool `mapstructure:"deprecated"`

ReplayHeight int64 `mapstructure:"replay_height"`

// Database backend: leveldb | memdb | cleveldb
DBBackend string `mapstructure:"db_backend"`

Expand Down Expand Up @@ -189,7 +196,7 @@ type BaseConfig struct {

// If true, query the ABCI app on connecting to a new peer
// so the app can decide if we should keep the connection or not
FilterPeers bool `mapstructure:"filter_peers"` // false
//FilterPeers bool `mapstructure:"filter_peers"` // false
}

// DefaultBaseConfig returns a default base configuration for a Tendermint node
Expand All @@ -206,7 +213,9 @@ func DefaultBaseConfig() BaseConfig {
LogFormat: LogFormatPlain,
ProfListenAddress: "",
FastSync: true,
FilterPeers: false,
Deprecated: false,
ReplayHeight: -1,
//FilterPeers: false,
DBBackend: "leveldb",
DBPath: "data",
}
Expand Down
9 changes: 5 additions & 4 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ moniker = "{{ .BaseConfig.Moniker }}"
# and verifying their commits
fast_sync = {{ .BaseConfig.FastSync }}

# If the blockchain is deprecated, run node with Deprecated will
# work in query only mode. Consensus engine and p2p gossip will be
# shutdown
deprecated = {{ .BaseConfig.Deprecated }}

# Database backend: leveldb | memdb | cleveldb
db_backend = "{{ .BaseConfig.DBBackend }}"

Expand Down Expand Up @@ -117,10 +122,6 @@ abci = "{{ .BaseConfig.ABCI }}"
# TCP or UNIX socket address for the profiling server to listen on
prof_laddr = "{{ .BaseConfig.ProfListenAddress }}"

# If true, query the ABCI app on connecting to a new peer
# so the app can decide if we should keep the connection or not
filter_peers = {{ .BaseConfig.FilterPeers }}

##### advanced configuration options #####

##### rpc server configuration options #####
Expand Down
42 changes: 34 additions & 8 deletions consensus/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"hash/crc32"
"io"
"reflect"
"runtime"

//"strconv"
//"strings"
"time"

abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
//auto "github.com/tendermint/tendermint/libs/autofile"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
Expand Down Expand Up @@ -235,7 +237,7 @@ func (h *Handshaker) NBlocks() int {
}

// TODO: retry the handshake/replay if it fails ?
func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
func (h *Handshaker) Handshake(proxyApp proxy.AppConns, config *cfg.BaseConfig) error {

// Handshake is done via ABCI Info on the query conn.
res, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
Expand All @@ -260,8 +262,12 @@ func (h *Handshaker) Handshake(proxyApp proxy.AppConns) error {
h.initialState.Version.Consensus.App = version.Protocol(res.AppVersion)
sm.SaveState(h.stateDB, h.initialState)

state := sm.LoadState(h.stateDB)
state.Version.Consensus.App = version.Protocol(res.AppVersion)
sm.SaveState(h.stateDB, state)

// Replay blocks up to the latest in the blockstore.
_, err = h.ReplayBlocks(h.initialState, appHash, blockHeight, proxyApp)
_, err = h.ReplayBlocks(h.initialState, appHash, blockHeight, proxyApp, config)
if err != nil {
return fmt.Errorf("Error on replay: %v", err)
}
Expand All @@ -281,6 +287,7 @@ func (h *Handshaker) ReplayBlocks(
appHash []byte,
appBlockHeight int64,
proxyApp proxy.AppConns,
config *cfg.BaseConfig,
) ([]byte, error) {
storeBlockHeight := h.store.Height()
stateBlockHeight := state.LastBlockHeight
Expand Down Expand Up @@ -355,7 +362,7 @@ func (h *Handshaker) ReplayBlocks(
// Either the app is asking for replay, or we're all synced up.
if appBlockHeight < storeBlockHeight {
// the app is behind, so replay blocks, but no need to go through WAL (state is already synced to store)
return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, false)
return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, false, config)

} else if appBlockHeight == storeBlockHeight {
// We're good!
Expand All @@ -368,7 +375,7 @@ func (h *Handshaker) ReplayBlocks(
if appBlockHeight < stateBlockHeight {
// the app is further behind than it should be, so replay blocks
// but leave the last block to go through the WAL
return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, true)
return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, true, config)

} else if appBlockHeight == stateBlockHeight {
// We haven't run Commit (both the state and app are one block behind),
Expand All @@ -385,7 +392,11 @@ func (h *Handshaker) ReplayBlocks(
if err != nil {
return nil, err
}
mockApp := newMockProxyApp(appHash, abciResponses)
res, err := proxyApp.Query().InfoSync(proxy.RequestInfo)
if err != nil {
return nil, fmt.Errorf("Error calling Info: %v", err)
}
mockApp := newMockProxyApp([]byte(res.Data), abciResponses)
h.logger.Info("Replay last block using mock app")
state, err = h.replayBlock(state, storeBlockHeight, mockApp)
return state.AppHash, err
Expand All @@ -397,7 +408,7 @@ func (h *Handshaker) ReplayBlocks(
return nil, nil
}

func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBlockHeight, storeBlockHeight int64, mutateState bool) ([]byte, error) {
func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBlockHeight, storeBlockHeight int64, mutateState bool, config *cfg.BaseConfig) ([]byte, error) {
// App is further behind than it should be, so we need to replay blocks.
// We replay all blocks from appBlockHeight+1.
//
Expand All @@ -409,6 +420,7 @@ func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBl
// If mutateState == true, the final block is replayed with h.replayBlock()

var appHash []byte
var cid types.CommitID
var err error
finalBlock := storeBlockHeight
if mutateState {
Expand All @@ -417,10 +429,24 @@ func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBl
for i := appBlockHeight + 1; i <= finalBlock; i++ {
h.logger.Info("Applying block", "height", i)
block := h.store.LoadBlock(i)
appHash, err = sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, state.LastValidators, h.stateDB)

if len(appHash) != 0 {
if !bytes.Equal(block.Header.AppHash, appHash) {
panic(fmt.Sprintf("AppHash mismatch: expected %s, actual %s", block.AppHash.String(), cmn.HexBytes(appHash).String()))
}
}

bz, err := sm.ExecCommitBlock(proxyApp.Consensus(), block, h.logger, state.LastValidators, h.stateDB)
if err != nil {
return nil, err
}
cid = types.UnmarshalCommitID(bz)
appHash = cid.Hash

if config.ReplayHeight > 0 && i >= config.ReplayHeight {
fmt.Printf("Replay from height %d to height %d successfully", appBlockHeight, config.ReplayHeight)
runtime.Goexit()
}

h.nBlocks++
}
Expand All @@ -434,7 +460,7 @@ func (h *Handshaker) replayBlocks(state sm.State, proxyApp proxy.AppConns, appBl
appHash = state.AppHash
}

return appHash, checkAppHash(state, appHash)
return appHash, sm.CheckAppHashAndShardingHash(state, cid)
}

// ApplyBlock on the proxyApp with the last block.
Expand Down
2 changes: 1 addition & 1 deletion consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo

handshaker := NewHandshaker(stateDB, state, blockStore, gdoc)
handshaker.SetEventBus(eventBus)
err = handshaker.Handshake(proxyApp)
err = handshaker.Handshake(proxyApp, &config)
if err != nil {
cmn.Exit(fmt.Sprintf("Error on handshake: %v", err))
}
Expand Down
12 changes: 12 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import (
//-----------------------------------------------------------------------------
// Errors

const (
deprecatedToShutdownInterval = 30
)

var (
ErrInvalidProposalSignature = errors.New("Error invalid proposal signature")
ErrInvalidProposalPOLRound = errors.New("Error invalid proposal POL round")
Expand Down Expand Up @@ -133,6 +137,7 @@ type ConsensusState struct {

// for reporting metrics
metrics *Metrics
Deprecated bool
}

// StateOption sets an optional parameter on the ConsensusState.
Expand Down Expand Up @@ -169,6 +174,7 @@ func NewConsensusState(
cs.doPrevote = cs.defaultDoPrevote
cs.setProposal = cs.defaultSetProposal

cs.Deprecated = state.Deprecated
cs.updateToState(state)

// Don't call scheduleRound0 yet.
Expand Down Expand Up @@ -622,6 +628,12 @@ func (cs *ConsensusState) receiveRoutine(maxSteps int) {
}()

for {
if cs.Deprecated {
cs.Logger.Info(fmt.Sprintf("this blockchain has been deprecated. %d seconds later, this node will be shutdown", deprecatedToShutdownInterval))
time.Sleep(deprecatedToShutdownInterval * time.Second)
cmn.Exit("Shutdown this blockchain node")
}

if maxSteps > 0 {
if cs.nSteps >= maxSteps {
cs.Logger.Info("reached max steps. exiting receive routine")
Expand Down
Loading