Skip to content

Commit

Permalink
Remove unit withTxBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoyangLiu committed Jul 18, 2019
1 parent e971d9a commit 3710685
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ func validateBasicTxMsgs(msgs []sdk.Msg) sdk.Error {
func (app *BaseApp) getContextWithCache(mode sdk.RunTxMode, tx sdk.Tx, txBytes []byte, txHash string) (sdk.Context,
sdk.CacheMultiStore, sdk.AccountCache) {
// Get the context
ctx := getState(app, mode).Ctx.WithTxBytes(txBytes).WithTx(tx)
ctx := getState(app, mode).Ctx.WithTx(tx)
// Simulate a DeliverTx
if mode == sdk.RunTxModeSimulate {
ctx = ctx.WithRunTxMode(mode)
Expand Down
6 changes: 0 additions & 6 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func NewContext(ms MultiStore, header abci.Header, runTxMode RunTxMode, logger l
c = c.WithBlockHeight(header.Height)
c = c.WithChainID(header.ChainID)
c = c.WithRunTxMode(runTxMode)
c = c.WithTxBytes(nil)
c = c.WithTx(nil)
c = c.WithLogger(logger)
c = c.WithVoteInfos(nil)
Expand Down Expand Up @@ -135,7 +134,6 @@ const (
contextKeyConsensusParams
contextKeyChainID
contextKeyRunTxMode
contextKeyTxBytes
contextKeyTx
contextKeyLogger
contextKeyVoteInfos
Expand All @@ -157,8 +155,6 @@ func (c Context) ConsensusParams() abci.ConsensusParams {

func (c Context) ChainID() string { return c.Value(contextKeyChainID).(string) }

func (c Context) TxBytes() []byte { return c.Value(contextKeyTxBytes).([]byte) }

func (c Context) Tx() Tx { return c.Value(contextKeyTx).(Tx) }

func (c Context) Logger() log.Logger { return c.Value(contextKeyLogger).(log.Logger) }
Expand Down Expand Up @@ -224,8 +220,6 @@ func (c Context) WithConsensusParams(params *abci.ConsensusParams) Context {

func (c Context) WithChainID(chainID string) Context { return c.withValue(contextKeyChainID, chainID) }

func (c Context) WithTxBytes(txBytes []byte) Context { return c.withValue(contextKeyTxBytes, txBytes) }

func (c Context) WithTx(tx Tx) Context { return c.withValue(contextKeyTx, tx) }

func (c Context) WithLogger(logger log.Logger) Context { return c.withValue(contextKeyLogger, logger) }
Expand Down
34 changes: 22 additions & 12 deletions types/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,12 @@ func TestContextWithCustom(t *testing.T) {
require.Panics(t, func() { ctx.BlockHeader() })
require.Panics(t, func() { ctx.BlockHeight() })
require.Panics(t, func() { ctx.ChainID() })
require.Panics(t, func() { ctx.TxBytes() })
require.Panics(t, func() { ctx.Logger() })
require.Panics(t, func() { ctx.VoteInfos() })

header := abci.Header{}
height := int64(1)
chainid := "chainid"
txbytes := []byte("txbytes")
logger := NewMockLogger()
voteinfos := []abci.VoteInfo{{}}

Expand All @@ -167,29 +165,28 @@ func TestContextWithCustom(t *testing.T) {
ctx = ctx.
WithBlockHeight(height).
WithChainID(chainid).
WithTxBytes(txbytes).
WithVoteInfos(voteinfos)
require.Equal(t, height, ctx.BlockHeight())
require.Equal(t, chainid, ctx.ChainID())
require.Equal(t, true, ctx.IsCheckTx())
require.Equal(t, txbytes, ctx.TxBytes())
require.Equal(t, logger, ctx.Logger())
require.Equal(t, voteinfos, ctx.VoteInfos())
}

func BenchmarkContextWithChainID(b *testing.B) {
ctx := types.NewContext(nil, abci.Header{}, types.RunTxModeDeliver, log.NewNopLogger())
height := int64(1)
chainid := "chainid"
voteinfos := []abci.VoteInfo{{}}
for n := 0; n < b.N; n++ {
ctx = ctx.WithChainID(chainid)
ctx = ctx.WithBlockHeight(height).
WithChainID(chainid).
WithVoteInfos(voteinfos)
}
}

func BenchmarkContextWithTxBytes(b *testing.B) {
ctx := types.NewContext(nil, abci.Header{}, types.RunTxModeDeliver, log.NewNopLogger())
txbytes := []byte("txbytes")
for n := 0; n < b.N; n++ {
ctx = ctx.WithTxBytes(txbytes)
_ = ctx.BlockHeight()
_ = ctx.ChainID()
_ = ctx.VoteInfos()
}
}

Expand All @@ -202,7 +199,20 @@ func BenchmarkContextWithTx(b *testing.B) {
msgs := []types.Msg{types.NewTestMsg(addr)}
sigs := []auth.StdSignature{}
tx = auth.NewStdTx(msgs, sigs, "", 0, nil)

height := int64(1)
chainid := "chainid"
voteinfos := []abci.VoteInfo{{}}
for n := 0; n < b.N; n++ {
ctx = ctx.WithBlockHeight(height).
WithChainID(chainid).
WithVoteInfos(voteinfos).
WithTx(tx)
}
for n := 0; n < b.N; n++ {
ctx = ctx.WithTx(tx)
_ = ctx.BlockHeight()
_ = ctx.ChainID()
_ = ctx.VoteInfos()
_ = ctx.Tx()
}
}

0 comments on commit 3710685

Please sign in to comment.