From df6046ccabe59d6b435813add65838f7f4b0867b Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Thu, 17 Jan 2019 19:48:20 +0800 Subject: [PATCH 1/2] add interest msg to pool --- baseapp/baseapp.go | 16 ++++++++++++---- baseapp/baseapp_test.go | 4 ++-- cmd/gaia/app/app.go | 2 +- cmd/gaia/app/app_test.go | 2 +- cmd/gaia/cmd/gaiadebug/hack.go | 2 +- docs/sdk/core/examples/app1.go | 2 +- docs/sdk/core/examples/app2.go | 2 +- docs/sdk/core/examples/app3.go | 2 +- docs/sdk/core/examples/app4.go | 2 +- server/mock/app.go | 2 +- types/coin.go | 4 ++-- types/pool.go | 34 +++++++++++++++++++++++++++++++++- types/tx_msg.go | 2 +- x/mock/app.go | 2 +- 14 files changed, 59 insertions(+), 19 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 2c4b1deb9..4243397b3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -49,6 +49,7 @@ type BaseApp struct { queryRouter QueryRouter // router for redirecting query calls codespacer *sdk.Codespacer // handle module codespacing isPublishAccountBalance bool + interestWithMsg bool TxDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx @@ -89,7 +90,7 @@ var _ abci.Application = (*BaseApp)(nil) // NOTE: The db is used to store the version number for now. // Accepts a user-defined TxDecoder // Accepts variable number of option functions, which act on the BaseApp to set configuration choices -func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, isPublish bool, options ...func(*BaseApp)) *BaseApp { +func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, isPublish, interestWithMsg bool, options ...func(*BaseApp)) *BaseApp { cache, err := lru.New(TxMsgCacheSize) if err != nil { panic(err) @@ -104,6 +105,7 @@ func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecod codespacer: sdk.NewCodespacer(), TxDecoder: txDecoder, isPublishAccountBalance: isPublish, + interestWithMsg: interestWithMsg, txMsgCache: cache, Pool: new(sdk.Pool), } @@ -828,8 +830,14 @@ func (app *BaseApp) RunTx(mode sdk.RunTxMode, txBytes []byte, tx sdk.Tx, txHash // only update state if all messages pass if result.IsOK() { - if (mode == sdk.RunTxModeDeliver || mode == sdk.RunTxModeDeliverAfterPre) && app.isPublishAccountBalance { - app.Pool.AddAddrs(msgs[0].GetInvolvedAddresses()) + if (mode == sdk.RunTxModeDeliver || mode == sdk.RunTxModeDeliverAfterPre) { + if app.isPublishAccountBalance{ + app.Pool.AddAddrs(msgs[0].GetInvolvedAddresses()) + } + if app.interestWithMsg{ + // Should we add all msg here with no distinction ? + app.Pool.AddMsgs([]sdk.Msg{msgs[0]}) + } } accountCache.Write() msCache.Write() @@ -934,7 +942,7 @@ func (app *BaseApp) Commit() (res abci.ResponseCommit) { // Empty the Deliver state app.DeliverState = nil - app.Pool.ClearTxRelatedAddrs() + app.Pool.Clear() return abci.ResponseCommit{ Data: commitID.Hash, diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index fc039ca85..964253074 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -37,7 +37,7 @@ func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { db := dbm.NewMemDB() codec := codec.New() registerTestCodec(codec) - return NewBaseApp(name, logger, db, testTxDecoder(codec), false, options...) + return NewBaseApp(name, logger, db, testTxDecoder(codec), false, false,options...) } func registerTestCodec(cdc *codec.Codec) { @@ -102,7 +102,7 @@ func (app *MockBaseApp) initFromStore(mainKey sdk.StoreKey) error { } func NewMockBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, isPublish bool, options ...func(*BaseApp)) *MockBaseApp { - return &MockBaseApp{NewBaseApp(name, logger, db, txDecoder, isPublish, options...)} + return &MockBaseApp{NewBaseApp(name, logger, db, txDecoder, isPublish, false,options...)} } //------------------------------------------------------------------------------------------ diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 7ad9b5b9f..04f160a72 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -75,7 +75,7 @@ type GaiaApp struct { func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false, baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false,false, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) var app = &GaiaApp{ diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index 7a60b017f..0b76ecd0d 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -34,7 +34,7 @@ type MockGaiaApp struct { func NewMockGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *MockGaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false, baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false,false, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) gApp := &GaiaApp{ diff --git a/cmd/gaia/cmd/gaiadebug/hack.go b/cmd/gaia/cmd/gaiadebug/hack.go index ace6e4292..5c66ae084 100644 --- a/cmd/gaia/cmd/gaiadebug/hack.go +++ b/cmd/gaia/cmd/gaiadebug/hack.go @@ -148,7 +148,7 @@ type GaiaApp struct { func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false, baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false, false,baseAppOptions...) bApp.SetCommitMultiStoreTracer(os.Stdout) // create your application object diff --git a/docs/sdk/core/examples/app1.go b/docs/sdk/core/examples/app1.go index b235f4f3a..def05c838 100644 --- a/docs/sdk/core/examples/app1.go +++ b/docs/sdk/core/examples/app1.go @@ -18,7 +18,7 @@ const ( func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp { // Create the base application object. - app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder, false) + app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder, false,false) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app2.go b/docs/sdk/core/examples/app2.go index bd3a08dee..ac5fcccf7 100644 --- a/docs/sdk/core/examples/app2.go +++ b/docs/sdk/core/examples/app2.go @@ -39,7 +39,7 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := NewCodec() // Create the base application object. - app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(cdc), false) + app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(cdc), false,false) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app3.go b/docs/sdk/core/examples/app3.go index 329c1905c..71f7f2e70 100644 --- a/docs/sdk/core/examples/app3.go +++ b/docs/sdk/core/examples/app3.go @@ -23,7 +23,7 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := UpdatedCodec() // Create the base application object. - app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc), false) + app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc), false,false) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app4.go b/docs/sdk/core/examples/app4.go index d13fe20f0..343412c42 100644 --- a/docs/sdk/core/examples/app4.go +++ b/docs/sdk/core/examples/app4.go @@ -22,7 +22,7 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := UpdatedCodec() // Create the base application object. - app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc), false) + app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc), false,false) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/server/mock/app.go b/server/mock/app.go index 04026fd8c..3632c7ed5 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -30,7 +30,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { capKeyMainStore := sdk.NewKVStoreKey("main") // Create BaseApp. - baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, false) + baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, false, false) // Set mounts for BaseApp's MultiStore. baseApp.MountStoresIAVL(capKeyMainStore) diff --git a/types/coin.go b/types/coin.go index c4efdc1e4..c485b992b 100644 --- a/types/coin.go +++ b/types/coin.go @@ -305,12 +305,12 @@ func ParseCoin(coinStr string) (coin Coin, err error) { } denomStr, amountStr := matches[2], matches[1] - amount, err := strconv.ParseInt(amountStr, 10, 64) + amount, err := strconv.Atoi(amountStr) if err != nil { return } - return Coin{denomStr, amount}, nil + return Coin{denomStr, int64(amount)}, nil } // ParseCoins will parse out a list of coins separated by commas. diff --git a/types/pool.go b/types/pool.go index 9ac20bd03..a701d42dc 100644 --- a/types/pool.go +++ b/types/pool.go @@ -11,6 +11,34 @@ import ( // deliver state type Pool struct { accounts sync.Map // save tx/gov related addresses (string wrapped bytes) to be published + + mesMux sync.Mutex + // We choose slice instead of map to store msg. Since Msg can be duplicated and is not hashable, + // and hash with msg.GetSignBytes cost a lot. + messages []Msg +} + +func (p *Pool) AddMsgs(msgs []Msg) { + p.mesMux.Lock() + defer p.mesMux.Unlock() + for _, m := range msgs { + p.messages = append(p.messages, m) + } +} + +func (p Pool) InterestMsgs(choose func(Msg) bool) []Msg { + p.mesMux.Lock() + defer p.mesMux.Unlock() + msgs := make([]Msg, 0, 0) + if p.messages == nil { + return msgs + } + for _, v := range p.messages { + if choose(v) { + msgs = append(msgs, v) + } + } + return msgs } func (p *Pool) AddAddrs(addrs []AccAddress) { @@ -28,6 +56,10 @@ func (p Pool) TxRelatedAddrs() []string { return addrs } -func (p *Pool) ClearTxRelatedAddrs() { +func (p *Pool) Clear() { p.accounts = sync.Map{} + + p.mesMux.Lock() + defer p.mesMux.Unlock() + p.messages = []Msg{} } diff --git a/types/tx_msg.go b/types/tx_msg.go index 9b10b99f1..88068ef76 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -28,7 +28,7 @@ type Msg interface { GetSigners() []AccAddress // Get involved addresses of this msg so that we can publish account balance change - GetInvolvedAddresses() []AccAddress + GetInvolvedAddresses() ([]AccAddress) } //__________________________________________________________ diff --git a/x/mock/app.go b/x/mock/app.go index a96418daa..836adb182 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -49,7 +49,7 @@ func NewApp() *App { // Create your application object app := &App{ - BaseApp: bam.NewBaseApp("mock", logger, db, auth.DefaultTxDecoder(cdc), false), + BaseApp: bam.NewBaseApp("mock", logger, db, auth.DefaultTxDecoder(cdc), false, false), Cdc: cdc, KeyMain: sdk.NewKVStoreKey("main"), KeyAccount: sdk.NewKVStoreKey("acc"), From 8f4f3b23fa587138474be99d39021ef5e72aeb4e Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Mon, 21 Jan 2019 14:52:33 +0800 Subject: [PATCH 2/2] do review change --- baseapp/baseapp.go | 50 ++++++++++++++++------------------ baseapp/baseapp_test.go | 18 ++++++------ cmd/gaia/app/app.go | 2 +- cmd/gaia/app/app_test.go | 2 +- cmd/gaia/cmd/gaiadebug/hack.go | 2 +- docs/sdk/core/examples/app1.go | 2 +- docs/sdk/core/examples/app2.go | 2 +- docs/sdk/core/examples/app3.go | 2 +- docs/sdk/core/examples/app4.go | 2 +- server/mock/app.go | 2 +- types/coin.go | 4 +-- types/config.go | 8 +++++- types/pool.go | 34 ++++------------------- types/tx_msg.go | 2 +- x/mock/app.go | 2 +- 15 files changed, 58 insertions(+), 76 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 4243397b3..935ed2185 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -41,15 +41,14 @@ const ( // BaseApp reflects the ABCI application implementation. type BaseApp struct { // initialized on creation - Logger log.Logger - name string // application name from abci.Info - db dbm.DB // common DB backend - cms sdk.CommitMultiStore // Main (uncached) state - router Router // handle any kind of message - queryRouter QueryRouter // router for redirecting query calls - codespacer *sdk.Codespacer // handle module codespacing - isPublishAccountBalance bool - interestWithMsg bool + Logger log.Logger + name string // application name from abci.Info + db dbm.DB // common DB backend + cms sdk.CommitMultiStore // Main (uncached) state + router Router // handle any kind of message + queryRouter QueryRouter // router for redirecting query calls + codespacer *sdk.Codespacer // handle module codespacing + collect sdk.CollectConfig TxDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx @@ -90,24 +89,23 @@ var _ abci.Application = (*BaseApp)(nil) // NOTE: The db is used to store the version number for now. // Accepts a user-defined TxDecoder // Accepts variable number of option functions, which act on the BaseApp to set configuration choices -func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, isPublish, interestWithMsg bool, options ...func(*BaseApp)) *BaseApp { +func NewBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, collectConfig sdk.CollectConfig, options ...func(*BaseApp)) *BaseApp { cache, err := lru.New(TxMsgCacheSize) if err != nil { panic(err) } app := &BaseApp{ - Logger: logger, - name: name, - db: db, - cms: store.NewCommitMultiStore(db), - router: NewRouter(), - queryRouter: NewQueryRouter(), - codespacer: sdk.NewCodespacer(), - TxDecoder: txDecoder, - isPublishAccountBalance: isPublish, - interestWithMsg: interestWithMsg, - txMsgCache: cache, - Pool: new(sdk.Pool), + Logger: logger, + name: name, + db: db, + cms: store.NewCommitMultiStore(db), + router: NewRouter(), + queryRouter: NewQueryRouter(), + codespacer: sdk.NewCodespacer(), + TxDecoder: txDecoder, + collect: collectConfig, + txMsgCache: cache, + Pool: new(sdk.Pool), } // Register the undefined & root codespaces, which should not be used by @@ -830,13 +828,13 @@ func (app *BaseApp) RunTx(mode sdk.RunTxMode, txBytes []byte, tx sdk.Tx, txHash // only update state if all messages pass if result.IsOK() { - if (mode == sdk.RunTxModeDeliver || mode == sdk.RunTxModeDeliverAfterPre) { - if app.isPublishAccountBalance{ + if mode == sdk.RunTxModeDeliver || mode == sdk.RunTxModeDeliverAfterPre { + if app.collect.CollectAccountBalance { app.Pool.AddAddrs(msgs[0].GetInvolvedAddresses()) } - if app.interestWithMsg{ + if app.collect.CollectTxs { // Should we add all msg here with no distinction ? - app.Pool.AddMsgs([]sdk.Msg{msgs[0]}) + app.Pool.AddTx(tx, txHash) } } accountCache.Write() diff --git a/baseapp/baseapp_test.go b/baseapp/baseapp_test.go index 964253074..9d0dfd9a2 100644 --- a/baseapp/baseapp_test.go +++ b/baseapp/baseapp_test.go @@ -37,7 +37,7 @@ func newBaseApp(name string, options ...func(*BaseApp)) *BaseApp { db := dbm.NewMemDB() codec := codec.New() registerTestCodec(codec) - return NewBaseApp(name, logger, db, testTxDecoder(codec), false, false,options...) + return NewBaseApp(name, logger, db, testTxDecoder(codec), sdk.CollectConfig{}, options...) } func registerTestCodec(cdc *codec.Codec) { @@ -101,8 +101,8 @@ func (app *MockBaseApp) initFromStore(mainKey sdk.StoreKey) error { return nil } -func NewMockBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, isPublish bool, options ...func(*BaseApp)) *MockBaseApp { - return &MockBaseApp{NewBaseApp(name, logger, db, txDecoder, isPublish, false,options...)} +func NewMockBaseApp(name string, logger log.Logger, db dbm.DB, txDecoder sdk.TxDecoder, collect sdk.CollectConfig, options ...func(*BaseApp)) *MockBaseApp { + return &MockBaseApp{NewBaseApp(name, logger, db, txDecoder, collect, options...)} } //------------------------------------------------------------------------------------------ @@ -124,7 +124,7 @@ func TestLoadVersion(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() name := t.Name() - app := NewMockBaseApp(name, logger, db, nil, false) + app := NewMockBaseApp(name, logger, db, nil, sdk.CollectConfig{}) // make a cap key and mount the store capKey := sdk.NewKVStoreKey("main") @@ -153,7 +153,7 @@ func TestLoadVersion(t *testing.T) { commitID2 := sdk.CommitID{2, res.Data} // reload with LoadLatestVersion - app = NewMockBaseApp(name, logger, db, nil, false) + app = NewMockBaseApp(name, logger, db, nil, sdk.CollectConfig{}) app.MountStoresIAVL(capKey) err = app.LoadLatestVersion(capKey) require.Nil(t, err) @@ -161,7 +161,7 @@ func TestLoadVersion(t *testing.T) { // reload with LoadVersion, see if you can commit the same block and get // the same result - app = NewMockBaseApp(name, logger, db, nil, false) + app = NewMockBaseApp(name, logger, db, nil, sdk.CollectConfig{}) app.MountStoresIAVL(capKey) err = app.LoadVersion(1, capKey) require.Nil(t, err) @@ -181,7 +181,7 @@ func testLoadVersionHelper(t *testing.T, app *MockBaseApp, expectedHeight int64, func TestOptionFunction(t *testing.T) { logger := defaultLogger() db := dbm.NewMemDB() - bap := NewMockBaseApp("starting name", logger, db, nil, false, testChangeNameHelper("new name")) + bap := NewMockBaseApp("starting name", logger, db, nil, sdk.CollectConfig{}, testChangeNameHelper("new name")) require.Equal(t, bap.name, "new name", "BaseApp should have had name changed via option function") } @@ -253,7 +253,7 @@ func TestInitChainer(t *testing.T) { // we can reload the same app later db := dbm.NewMemDB() logger := defaultLogger() - app := NewMockBaseApp(name, logger, db, nil, false) + app := NewMockBaseApp(name, logger, db, nil, sdk.CollectConfig{}) capKey := sdk.NewKVStoreKey("main") capKey2 := sdk.NewKVStoreKey("key2") app.MountStoresIAVL(capKey, capKey2) @@ -297,7 +297,7 @@ func TestInitChainer(t *testing.T) { require.Equal(t, value, res.Value) // reload app - app = NewMockBaseApp(name, logger, db, nil, false) + app = NewMockBaseApp(name, logger, db, nil, sdk.CollectConfig{}) app.SetInitChainer(initChainer) app.MountStoresIAVL(capKey, capKey2) err = app.LoadLatestVersion(capKey) // needed to make stores non-nil diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 04f160a72..ac093d5e1 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -75,7 +75,7 @@ type GaiaApp struct { func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false,false, baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) var app = &GaiaApp{ diff --git a/cmd/gaia/app/app_test.go b/cmd/gaia/app/app_test.go index 0b76ecd0d..faf526af4 100644 --- a/cmd/gaia/app/app_test.go +++ b/cmd/gaia/app/app_test.go @@ -34,7 +34,7 @@ type MockGaiaApp struct { func NewMockGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptions ...func(*bam.BaseApp)) *MockGaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false,false, baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}, baseAppOptions...) bApp.SetCommitMultiStoreTracer(traceStore) gApp := &GaiaApp{ diff --git a/cmd/gaia/cmd/gaiadebug/hack.go b/cmd/gaia/cmd/gaiadebug/hack.go index 5c66ae084..524aecde0 100644 --- a/cmd/gaia/cmd/gaiadebug/hack.go +++ b/cmd/gaia/cmd/gaiadebug/hack.go @@ -148,7 +148,7 @@ type GaiaApp struct { func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseApp)) *GaiaApp { cdc := MakeCodec() - bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), false, false,baseAppOptions...) + bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}, baseAppOptions...) bApp.SetCommitMultiStoreTracer(os.Stdout) // create your application object diff --git a/docs/sdk/core/examples/app1.go b/docs/sdk/core/examples/app1.go index def05c838..92591bc48 100644 --- a/docs/sdk/core/examples/app1.go +++ b/docs/sdk/core/examples/app1.go @@ -18,7 +18,7 @@ const ( func NewApp1(logger log.Logger, db dbm.DB) *bapp.BaseApp { // Create the base application object. - app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder, false,false) + app := bapp.NewBaseApp(app1Name, logger, db, tx1Decoder, sdk.CollectConfig{}) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app2.go b/docs/sdk/core/examples/app2.go index ac5fcccf7..0dc7560f7 100644 --- a/docs/sdk/core/examples/app2.go +++ b/docs/sdk/core/examples/app2.go @@ -39,7 +39,7 @@ func NewApp2(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := NewCodec() // Create the base application object. - app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(cdc), false,false) + app := bapp.NewBaseApp(app2Name, logger, db, tx2Decoder(cdc), sdk.CollectConfig{}) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app3.go b/docs/sdk/core/examples/app3.go index 71f7f2e70..6e3e0819f 100644 --- a/docs/sdk/core/examples/app3.go +++ b/docs/sdk/core/examples/app3.go @@ -23,7 +23,7 @@ func NewApp3(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := UpdatedCodec() // Create the base application object. - app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc), false,false) + app := bapp.NewBaseApp(app3Name, logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/docs/sdk/core/examples/app4.go b/docs/sdk/core/examples/app4.go index 343412c42..ffe0120f8 100644 --- a/docs/sdk/core/examples/app4.go +++ b/docs/sdk/core/examples/app4.go @@ -22,7 +22,7 @@ func NewApp4(logger log.Logger, db dbm.DB) *bapp.BaseApp { cdc := UpdatedCodec() // Create the base application object. - app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc), false,false) + app := bapp.NewBaseApp(app4Name, logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}) // Create a key for accessing the account store. keyAccount := sdk.NewKVStoreKey("acc") diff --git a/server/mock/app.go b/server/mock/app.go index 3632c7ed5..17e25f55e 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -30,7 +30,7 @@ func NewApp(rootDir string, logger log.Logger) (abci.Application, error) { capKeyMainStore := sdk.NewKVStoreKey("main") // Create BaseApp. - baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, false, false) + baseApp := bam.NewBaseApp("kvstore", logger, db, decodeTx, sdk.CollectConfig{}) // Set mounts for BaseApp's MultiStore. baseApp.MountStoresIAVL(capKeyMainStore) diff --git a/types/coin.go b/types/coin.go index c485b992b..c4efdc1e4 100644 --- a/types/coin.go +++ b/types/coin.go @@ -305,12 +305,12 @@ func ParseCoin(coinStr string) (coin Coin, err error) { } denomStr, amountStr := matches[2], matches[1] - amount, err := strconv.Atoi(amountStr) + amount, err := strconv.ParseInt(amountStr, 10, 64) if err != nil { return } - return Coin{denomStr, int64(amount)}, nil + return Coin{denomStr, amount}, nil } // ParseCoins will parse out a list of coins separated by commas. diff --git a/types/config.go b/types/config.go index 6cd000234..7b10bd38a 100644 --- a/types/config.go +++ b/types/config.go @@ -102,4 +102,10 @@ func (config *Config) GetBech32ValidatorPubPrefix() string { // GetBech32ConsensusPubPrefix returns the Bech32 prefix for consensus node public key func (config *Config) GetBech32ConsensusPubPrefix() string { return config.bech32AddressPrefix["consensus_pub"] -} \ No newline at end of file +} + +// CollectConfig is the structure that holds configuration parameters whether to collect specified info during apply blocks. +type CollectConfig struct { + CollectAccountBalance bool + CollectTxs bool +} diff --git a/types/pool.go b/types/pool.go index a701d42dc..fc8deaf6e 100644 --- a/types/pool.go +++ b/types/pool.go @@ -11,34 +11,15 @@ import ( // deliver state type Pool struct { accounts sync.Map // save tx/gov related addresses (string wrapped bytes) to be published - - mesMux sync.Mutex - // We choose slice instead of map to store msg. Since Msg can be duplicated and is not hashable, - // and hash with msg.GetSignBytes cost a lot. - messages []Msg + txs sync.Map } -func (p *Pool) AddMsgs(msgs []Msg) { - p.mesMux.Lock() - defer p.mesMux.Unlock() - for _, m := range msgs { - p.messages = append(p.messages, m) - } +func (p *Pool) AddTx(tx Tx, txHash string) { + p.txs.Store(txHash, tx) } -func (p Pool) InterestMsgs(choose func(Msg) bool) []Msg { - p.mesMux.Lock() - defer p.mesMux.Unlock() - msgs := make([]Msg, 0, 0) - if p.messages == nil { - return msgs - } - for _, v := range p.messages { - if choose(v) { - msgs = append(msgs, v) - } - } - return msgs +func (p Pool) GetTxs() sync.Map{ + return p.txs } func (p *Pool) AddAddrs(addrs []AccAddress) { @@ -58,8 +39,5 @@ func (p Pool) TxRelatedAddrs() []string { func (p *Pool) Clear() { p.accounts = sync.Map{} - - p.mesMux.Lock() - defer p.mesMux.Unlock() - p.messages = []Msg{} + p.txs = sync.Map{} } diff --git a/types/tx_msg.go b/types/tx_msg.go index 88068ef76..9b10b99f1 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -28,7 +28,7 @@ type Msg interface { GetSigners() []AccAddress // Get involved addresses of this msg so that we can publish account balance change - GetInvolvedAddresses() ([]AccAddress) + GetInvolvedAddresses() []AccAddress } //__________________________________________________________ diff --git a/x/mock/app.go b/x/mock/app.go index 836adb182..8f87635bb 100644 --- a/x/mock/app.go +++ b/x/mock/app.go @@ -49,7 +49,7 @@ func NewApp() *App { // Create your application object app := &App{ - BaseApp: bam.NewBaseApp("mock", logger, db, auth.DefaultTxDecoder(cdc), false, false), + BaseApp: bam.NewBaseApp("mock", logger, db, auth.DefaultTxDecoder(cdc), sdk.CollectConfig{}), Cdc: cdc, KeyMain: sdk.NewKVStoreKey("main"), KeyAccount: sdk.NewKVStoreKey("acc"),