Skip to content

Commit

Permalink
tendermint version upgrade to v0.27.3
Browse files Browse the repository at this point in the history
  • Loading branch information
TokenxyWZY authored and kauchy committed Jan 8, 2019
1 parent ee3a558 commit 43a09cb
Show file tree
Hide file tree
Showing 38 changed files with 1,021 additions and 343 deletions.
6 changes: 3 additions & 3 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ func TestAccountMarshal(t *testing.T) {
err = baseAccount.SetNonce(int64(7))
require.Nil(t, err)

add_binary, err := cdc.MarshalBinary(baseAccount)
add_binary, err := cdc.MarshalBinaryLengthPrefixed(baseAccount)
require.Nil(t, err)

another_add := BaseAccount{}
another_json := []byte{}
err = cdc.UnmarshalBinary(add_binary, &another_add)
err = cdc.UnmarshalBinaryLengthPrefixed(add_binary, &another_add)
require.Nil(t, err)
require.Equal(t, baseAccount, another_add)

// error on bad bytes
another_add = BaseAccount{}
another_json = []byte{}
err = cdc.UnmarshalBinary(add_binary[:len(add_binary)/2], &another_json)
err = cdc.UnmarshalBinaryLengthPrefixed(add_binary[:len(add_binary)/2], &another_json)
require.NotNil(t, err)

}
Expand Down
37 changes: 22 additions & 15 deletions baseabci/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ type BaseApp struct {
// Volatile
// checkState is set on initialization and reset on Commit.
// deliverState is set in InitChain and BeginBlock and cleared on Commit.
checkState *state // for CheckTx
deliverState *state // for DeliverTx
signedValidators []abci.SigningValidator // absent validators from begin block
checkState *state // for CheckTx
deliverState *state // for DeliverTx
voteInfos []abci.VoteInfo // absent validators from begin block

//--------------------------------------------------------------

Expand Down Expand Up @@ -283,15 +283,20 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) (res abc
var result interface{}
switch path[1] {
case "version":
result = version.Version
return abci.ResponseQuery{
Code: uint32(types.CodeOK),
Codespace: string(types.CodespaceRoot),
Value: []byte(version.GetVersion()),
}
default:
result = types.ErrUnknownRequest(fmt.Sprintf("Unknown query: %s", path)).Result()
}

value := app.cdc.MustMarshalBinaryBare(result)
return abci.ResponseQuery{
Code: uint32(types.ABCICodeOK),
Value: value,
Code: uint32(types.CodeOK),
Codespace: string(types.CodespaceRoot),
Value: value,
}
}
msg := "Expected second parameter to be either simulate or version, neither was present"
Expand All @@ -309,13 +314,14 @@ func handlerCustomQuery(app *BaseApp, path []string, req abci.RequestQuery) (res

if err != nil {
return abci.ResponseQuery{
Code: uint32(err.ABCICode()),
Log: err.ABCILog(),
Code: uint32(err.Code()),
Codespace: string(err.Codespace()),
Log: err.ABCILog(),
}
}

return abci.ResponseQuery{
Code: uint32(types.ABCICodeOK),
Code: uint32(types.CodeOK),
Value: bz,
}

Expand Down Expand Up @@ -360,7 +366,7 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
}

// set the signed validators for addition to context in deliverTx
app.signedValidators = req.LastCommitInfo.GetValidators()
app.voteInfos = req.LastCommitInfo.GetVotes()

return
}
Expand Down Expand Up @@ -398,8 +404,8 @@ func toResponseCheckTx(result types.Result) abci.ResponseCheckTx {
Code: uint32(result.Code),
Data: result.Data,
Log: result.Log,
GasWanted: result.GasWanted,
GasUsed: result.GasUsed,
GasWanted: int64(result.GasWanted),
GasUsed: int64(result.GasUsed),
Tags: result.Tags,
}
}
Expand Down Expand Up @@ -596,7 +602,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
}

//初始化context相关数据
ctx := app.deliverState.ctx.WithTxBytes(txBytes).WithSigningValidators(app.signedValidators)
ctx := app.deliverState.ctx.WithTxBytes(txBytes).WithVoteInfos(app.voteInfos)

switch implTx := tx.(type) {
case *txs.TxStd:
Expand All @@ -614,10 +620,11 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
func toResponseDeliverTx(result types.Result) abci.ResponseDeliverTx {
return abci.ResponseDeliverTx{
Code: uint32(result.Code),
Codespace: string(result.Codespace),
Data: result.Data,
Log: result.Log,
GasWanted: result.GasWanted,
GasUsed: result.GasUsed,
GasWanted: int64(result.GasWanted),
GasUsed: int64(result.GasUsed),
Tags: result.Tags,
}
}
Expand Down
10 changes: 5 additions & 5 deletions baseabci/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,19 +202,19 @@ func TestTxQcpResult(t *testing.T) {

for i := uint64(1); i < 10; i++ {

var code int64
var code types.CodeType
seed := rand.Int63n(10)

if seed > int64(5) {
code = int64(0)
code = types.CodeOK
} else {
code = int64(1)
code = types.CodeInternal
}

qcpResult := &txs.QcpTxResult{
Result: types.Result{
Code: types.ABCICodeType(code),
GasUsed: types.OneInt().Int64(),
Code: code,
GasUsed: types.OneUint().Uint64(),
Tags: types.Tags{
types.MakeTag("key", []byte("value")),
},
Expand Down
2 changes: 1 addition & 1 deletion client/block/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func tryDecodeValue(cdc *go_amino.Codec, bz []byte, useKVPairFlag bool) (interfa

if useKVPairFlag {
var vKVPair []store.KVPair
err = cdc.UnmarshalBinary(bz, &vKVPair)
err = cdc.UnmarshalBinaryLengthPrefixed(bz, &vKVPair)
if err == nil {
var pairResults []kvPairResult
for _, pair := range vKVPair {
Expand Down
4 changes: 2 additions & 2 deletions client/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (ctx CLIContext) query(path string, key cmn.HexBytes) (res []byte, err erro
}

opts := rpcclient.ABCIQueryOptions{
Height: ctx.Height,
Trusted: ctx.TrustNode,
Height: ctx.Height,
Prove: ctx.TrustNode,
}

result, err := node.ABCIQueryWithOptions(path, key, opts)
Expand Down
2 changes: 1 addition & 1 deletion client/qcp/qcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func QueryQcpChainsInfo(ctx context.CLIContext) ([]qcpChainsResult, error) {
}

var kvPair []store.KVPair
err = ctx.Codec.UnmarshalBinary(res, &kvPair)
err = ctx.Codec.UnmarshalBinaryLengthPrefixed(res, &kvPair)
if err != nil {
return nil, err
}
Expand Down
62 changes: 41 additions & 21 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package context
import (
"context"
"sync"
"time"

"github.com/QOSGroup/qbase/mapper"

Expand Down Expand Up @@ -36,7 +37,7 @@ type Context struct {

// create a new context
// nolint: unparam
func NewContext(ms store.MultiStore, header abci.Header, isCheckTx bool, logger log.Logger, registeSeedMapper map[string]mapper.IMapper) Context {
func NewContext(ms store.MultiStore, header abci.Header, isCheckTx bool, logger log.Logger, registSeedMapper map[string]mapper.IMapper) Context {
c := Context{
Context: context.Background(),
pst: newThePast(),
Expand All @@ -49,8 +50,10 @@ func NewContext(ms store.MultiStore, header abci.Header, isCheckTx bool, logger
c = c.WithIsCheckTx(isCheckTx)
c = c.WithTxBytes(nil)
c = c.WithLogger(logger)
c = c.WithSigningValidators(nil)
c = c.withRegisteredMap(registeSeedMapper)
c = c.WithVoteInfos(nil)
c = c.WithConsensusParams(nil)
c = c.WithMinimumFees([]types.Coin{&types.BaseCoin{}})
c = c.withRegisteredMap(registSeedMapper)
c = c.copyKVStoreMapperFromSeed()
return c
}
Expand All @@ -77,12 +80,12 @@ func (c Context) Value(key interface{}) interface{} {

// KVStore fetches a KVStore from the MultiStore.
func (c Context) KVStore(key store.StoreKey) store.KVStore {
return c.multiStore().GetKVStore(key)
return c.MultiStore().GetKVStore(key)
}

// TransientStore fetches a TransientStore from the MultiStore.
func (c Context) TransientStore(key store.StoreKey) store.KVStore {
return c.multiStore().GetKVStore(key)
return c.MultiStore().GetKVStore(key)
}

//----------------------------------------
Expand Down Expand Up @@ -146,12 +149,13 @@ const (
contextKeyBlockHeader
contextKeyBlockHeight
contextKeyConsensusParams
contextKeyChainID // chainId 与 qscName相同
contextKeyChainID
contextKeyIsCheckTx
contextKeyTxBytes
contextKeyLogger
contextKeySigningValidators
contextKeyVoteInfos
contextKeyGasMeter
contextKeyBlockGasMeter
contextKeyMinimumFees
//增加特定的context key
contextKeyBlockTxIndex // tx在block中的索引
Expand All @@ -166,16 +170,20 @@ const ContextKeySigners contextKey = 99999
// NOTE: Do not expose MultiStore.
// MultiStore exposes all the keys.
// Instead, pass the context and the store key.
func (c Context) multiStore() store.MultiStore {
func (c Context) MultiStore() store.MultiStore {
return c.Value(contextKeyMultiStore).(store.MultiStore)
}

func (c Context) BlockHeader() abci.Header { return c.Value(contextKeyBlockHeader).(abci.Header) }

func (c Context) BlockHeight() int64 { return c.Value(contextKeyBlockHeight).(int64) }

func (c Context) ConsensusParams() abci.ConsensusParams {
return c.Value(contextKeyConsensusParams).(abci.ConsensusParams)
func (c Context) ConsensusParams() *abci.ConsensusParams {
return c.Value(contextKeyConsensusParams).(*abci.ConsensusParams)
}

func (c Context) VoteInfos() []abci.VoteInfo {
return c.Value(contextKeyVoteInfos).([]abci.VoteInfo)
}

func (c Context) ChainID() string { return c.Value(contextKeyChainID).(string) }
Expand All @@ -184,10 +192,6 @@ func (c Context) TxBytes() []byte { return c.Value(contextKeyTxBytes).([]byte) }

func (c Context) Logger() log.Logger { return c.Value(contextKeyLogger).(log.Logger) }

func (c Context) SigningValidators() []abci.SigningValidator {
return c.Value(contextKeySigningValidators).([]abci.SigningValidator)
}

func (c Context) GasMeter() types.GasMeter { return c.Value(contextKeyGasMeter).(types.GasMeter) }

func (c Context) IsCheckTx() bool { return c.Value(contextKeyIsCheckTx).(bool) }
Expand Down Expand Up @@ -217,16 +221,28 @@ func (c Context) WithBlockHeader(header abci.Header) Context {
return c.withValue(contextKeyBlockHeader, header)
}

func (c Context) WithBlockHeight(height int64) Context {
return c.withValue(contextKeyBlockHeight, height)
func (c Context) WithBlockTime(newTime time.Time) Context {
newHeader := c.BlockHeader()
newHeader.Time = newTime
return c.WithBlockHeader(newHeader)
}

func (c Context) WithProposer(addr types.Address) Context {
newHeader := c.BlockHeader()
newHeader.ProposerAddress = addr.Bytes()
return c.WithBlockHeader(newHeader)
}

func (c Context) WithBlockHeight(height int64) Context {
newHeader := c.BlockHeader()
newHeader.Height = height
return c.withValue(contextKeyBlockHeight, height).withValue(contextKeyBlockHeader, newHeader)
}
func (c Context) WithConsensusParams(params *abci.ConsensusParams) Context {
if params == nil {
return c
}
return c.withValue(contextKeyConsensusParams, params).
WithGasMeter(types.NewGasMeter(params.TxSize.MaxGas))
return c.withValue(contextKeyConsensusParams, params)
}

func (c Context) WithChainID(chainID string) Context { return c.withValue(contextKeyChainID, chainID) }
Expand All @@ -235,8 +251,8 @@ func (c Context) WithTxBytes(txBytes []byte) Context { return c.withValue(contex

func (c Context) WithLogger(logger log.Logger) Context { return c.withValue(contextKeyLogger, logger) }

func (c Context) WithSigningValidators(SigningValidators []abci.SigningValidator) Context {
return c.withValue(contextKeySigningValidators, SigningValidators)
func (c Context) WithVoteInfos(VoteInfos []abci.VoteInfo) Context {
return c.withValue(contextKeyVoteInfos, VoteInfos)
}

//
Expand Down Expand Up @@ -270,6 +286,10 @@ func (c Context) WithGasMeter(meter types.GasMeter) Context {
return c.withValue(contextKeyGasMeter, meter)
}

func (c Context) WithBlockGasMeter(meter types.GasMeter) Context {
return c.withValue(contextKeyBlockGasMeter, meter)
}

func (c Context) WithIsCheckTx(isCheckTx bool) Context {
return c.withValue(contextKeyIsCheckTx, isCheckTx)
}
Expand All @@ -293,7 +313,7 @@ func (c Context) ResetBlockTxIndex() Context {
// Cache the multistore and return a new cached context. The cached context is
// written to the context when writeCache is called.
func (c Context) CacheContext() (cc Context, writeCache func()) {
cms := c.multiStore().CacheMultiStore()
cms := c.MultiStore().CacheMultiStore()
cc = c.WithMultiStore(cms)
return cc, cms.Write
}
Expand Down
9 changes: 4 additions & 5 deletions context/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func TestContextWithCustom(t *testing.T) {
require.Panics(t, func() { ctx.ChainID() })
require.Panics(t, func() { ctx.TxBytes() })
require.Panics(t, func() { ctx.Logger() })
require.Panics(t, func() { ctx.SigningValidators() })
require.Panics(t, func() { ctx.VoteInfos() })
require.Panics(t, func() { ctx.GasMeter() })

header := abci.Header{}
Expand All @@ -165,7 +165,7 @@ func TestContextWithCustom(t *testing.T) {
ischeck := true
txbytes := []byte("txbytes")
logger := NewMockLogger()
signvals := []abci.SigningValidator{{}}
signvals := []abci.VoteInfo{{}}
meter := types.NewGasMeter(10000)
minFees := make([]types.Coin, 1)
blockTxIndex := int64(100)
Expand All @@ -178,19 +178,18 @@ func TestContextWithCustom(t *testing.T) {
WithBlockHeight(height).
WithChainID(chainid).
WithTxBytes(txbytes).
WithSigningValidators(signvals).
WithVoteInfos(signvals).
WithGasMeter(meter).
WithMinimumFees(minFees).
WithBlockTxIndex(blockTxIndex).
WithTxQcpResultHandler(handerler)

require.Equal(t, header, ctx.BlockHeader())
require.Equal(t, height, ctx.BlockHeight())
require.Equal(t, chainid, ctx.ChainID())
require.Equal(t, ischeck, ctx.IsCheckTx())
require.Equal(t, txbytes, ctx.TxBytes())
require.Equal(t, logger, ctx.Logger())
require.Equal(t, signvals, ctx.SigningValidators())
require.Equal(t, signvals, ctx.VoteInfos())
require.Equal(t, meter, ctx.GasMeter())
require.Equal(t, blockTxIndex, ctx.BlockTxIndex())

Expand Down
Loading

0 comments on commit 43a09cb

Please sign in to comment.