From fc8535d9a3001027baa18411f96b97fe34e68f2b Mon Sep 17 00:00:00 2001 From: aakash4dev Date: Tue, 25 Jun 2024 16:22:38 +0530 Subject: [PATCH] Introduced new field TrackStationType in node config. Made the tracksbft to process different blockchains differently to make batches of transactions. Renamed and refactored the `getBalance.go`, `storePod.go`, and `tracksTxUtils.go` files which are related to transaction tracking and pod storing. These files were broken down into `evmGetBalance.go`, `evmStorePod.go` and `evmUtils.go` respectively to better indicate that these functionalities are specific to the Ethereum Virtual Machine. Adjustments were also made in `kv.go` to account for the changes in previous files. --- CHANGELOG.md | 22 ++++++------- README.md | 4 +-- UPGRADING.md | 6 ++-- config/config.go | 7 +++- node/node.go | 8 +++-- rpc/core/tracks.go | 3 +- state/indexer/block/kv/util.go | 5 +-- state/indexer/sink/psql/backport.go | 2 +- state/txindex/indexer.go | 2 +- state/txindex/indexer_service.go | 9 +++++- .../kv/{getBalance.go => evmGetBalance.go} | 3 +- .../kv/{storePod.go => evmStorePod.go} | 7 ++-- .../kv/{tracksTxUtils.go => evmUtils.go} | 0 state/txindex/kv/kv.go | 32 ++++++++++--------- state/txindex/null/null.go | 2 +- test/e2e/generator/generate.go | 2 ++ 16 files changed, 69 insertions(+), 45 deletions(-) rename state/txindex/kv/{getBalance.go => evmGetBalance.go} (93%) rename state/txindex/kv/{storePod.go => evmStorePod.go} (97%) rename state/txindex/kv/{tracksTxUtils.go => evmUtils.go} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85b1cad..7ecaaaa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,7 +75,7 @@ that code. *Feb 27, 2023* This is the first official release of CometBFT - a fork of [Tendermint -Core](https://github.com/airchains-network/tracksbft). This particular release is +Core](https://github.com/tendermint/tendermint). This particular release is intended to be compatible with the Tendermint Core v0.34 release series. For details as to how to upgrade to CometBFT from Tendermint Core, please see @@ -118,7 +118,7 @@ to this release! send messages, as opposed to the blocking `SendEnvelope` method. It is unclear whether this has a meaningful impact on P2P performance, but this patch does correct the underlying behaviour to what it should be - ([tendermint/tendermint\#9936](https://github.com/airchains-network/tracksbft/pull/9936)) + ([tendermint/tendermint\#9936](https://github.com/tendermint/tendermint/pull/9936)) ### DEPENDENCIES @@ -128,19 +128,19 @@ to this release! - Bump tm-load-test to v1.3.0 to remove implicit dependency on Tendermint Core ([\#165](https://github.com/cometbft/cometbft/pull/165)) - `[crypto]` Update to use btcec v2 and the latest btcutil - ([tendermint/tendermint\#9787](https://github.com/airchains-network/tracksbft/pull/9787): + ([tendermint/tendermint\#9787](https://github.com/tendermint/tendermint/pull/9787): @wcsiu) ### FEATURES - `[rpc]` Add `match_event` query parameter to indicate to the RPC that it should match events _within_ attributes, not only within a height - ([tendermint/tendermint\#9759](https://github.com/airchains-network/tracksbft/pull/9759)) + ([tendermint/tendermint\#9759](https://github.com/tendermint/tendermint/pull/9759)) ### IMPROVEMENTS - `[e2e]` Add functionality for uncoordinated (minor) upgrades - ([\#56](https://github.com/airchains-network/tracksbft/pull/56)) + ([\#56](https://github.com/tendermint/tendermint/pull/56)) - `[tools/tm-signer-harness]` Remove the folder as it is unused ([\#136](https://github.com/cometbft/cometbft/issues/136)) - Append the commit hash to the version of CometBFT being built @@ -151,22 +151,22 @@ to this release! - `[consensus]` Add `consensus_block_gossip_parts_received` and `consensus_step_duration_seconds` metrics in order to aid in investigating the impact of database compaction on consensus performance - ([tendermint/tendermint\#9733](https://github.com/airchains-network/tracksbft/pull/9733)) + ([tendermint/tendermint\#9733](https://github.com/tendermint/tendermint/pull/9733)) - `[state/kvindexer]` Add `match.event` keyword to support condition evaluation based on the event the attributes belong to - ([tendermint/tendermint\#9759](https://github.com/airchains-network/tracksbft/pull/9759)) + ([tendermint/tendermint\#9759](https://github.com/tendermint/tendermint/pull/9759)) - `[p2p]` Reduce log spam through reducing log level of "Dialing peer" and "Added peer" messages from info to debug - ([tendermint/tendermint\#9764](https://github.com/airchains-network/tracksbft/pull/9764): + ([tendermint/tendermint\#9764](https://github.com/tendermint/tendermint/pull/9764): @faddat) - `[consensus]` Reduce bandwidth consumption of consensus votes by roughly 50% through fixing a small logic bug - ([tendermint/tendermint\#9776](https://github.com/airchains-network/tracksbft/pull/9776)) + ([tendermint/tendermint\#9776](https://github.com/tendermint/tendermint/pull/9776)) --- CometBFT is a fork of [Tendermint -Core](https://github.com/airchains-network/tracksbft) as of late December 2022. +Core](https://github.com/tendermint/tendermint) as of late December 2022. ## Bug bounty @@ -176,5 +176,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/cosmos). For changes released before the creation of CometBFT, please refer to the Tendermint Core -[CHANGELOG.md](https://github.com/airchains-network/tracksbft/blob/a9feb1c023e172b542c972605311af83b777855b/CHANGELOG.md). +[CHANGELOG.md](https://github.com/tendermint/tendermint/blob/a9feb1c023e172b542c972605311af83b777855b/CHANGELOG.md). diff --git a/README.md b/README.md index 8e78af8..a59cb7f 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ You can find more information about the Switchyard blockchain [here](https://git To use this project as a library in your blockchain project, update the `go.mod` file as follows: ```go -github.com/tendermint/tendermint => github.com/airchains-network/tracksbft v0.0.1 +github.com/tendermint/tendermint => github.com/tendermint/tendermint v0.0.1 ``` Alternatively, you can run the following command and then replace all `tendermint/cometbft` library imports in your blockchain project with `tracksbft`: ```bash -go get github.com/airchains-network/tracksbft +go get github.com/tendermint/tendermint ``` ## Minimum Requirements diff --git a/UPGRADING.md b/UPGRADING.md index 0194856..7cccd3b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -23,7 +23,7 @@ v0.34.24, or Informal Systems' public fork), you can upgrade to CometBFT v0.34.27 by replacing your dependency in your `go.mod` file: ```bash -go mod edit -replace github.com/airchains-network/tracksbft=github.com/cometbft/cometbft@v0.34.27 +go mod edit -replace github.com/tendermint/tendermint=github.com/cometbft/cometbft@v0.34.27 ``` We make use of the original module URL in order to minimize the impact of @@ -60,9 +60,9 @@ If you run into any trouble with this upgrade, please [contact us][discussions]. For historical upgrading instructions for Tendermint Core v0.34.24 and earlier, please see the [Tendermint Core upgrading instructions][tmupgrade]. -[v03424]: https://github.com/airchains-network/tracksbft/releases/tag/v0.34.24 +[v03424]: https://github.com/tendermint/tendermint/releases/tag/v0.34.24 [v03425]: https://github.com/informalsystems/tendermint/releases/tag/v0.34.25 [v03426]: https://github.com/informalsystems/tendermint/releases/tag/v0.34.26 [discussions]: https://github.com/cometbft/cometbft/discussions -[tmupgrade]: https://github.com/airchains-network/tracksbft/blob/35581cf54ec436b8c37fabb43fdaa3f48339a170/UPGRADING.md +[tmupgrade]: https://github.com/tendermint/tendermint/blob/35581cf54ec436b8c37fabb43fdaa3f48339a170/UPGRADING.md [go120]: https://go.dev/blog/go1.20 diff --git a/config/config.go b/config/config.go index 2a41e07..9028a0f 100644 --- a/config/config.go +++ b/config/config.go @@ -305,6 +305,8 @@ func (cfg BaseConfig) ValidateBasic() error { type RPCConfig struct { RootDir string `mapstructure:"home"` + TrackStationType string `mapstructure:"track_station_type"` + // TCP or UNIX socket address for the RPC server to listen on ListenAddress string `mapstructure:"laddr"` @@ -412,14 +414,17 @@ type RPCConfig struct { // DefaultRPCConfig returns a default configuration for the RPC server func DefaultRPCConfig() *RPCConfig { + return &RPCConfig{ + + TrackStationType: "none", // evm cosmwasm svm + ListenAddress: "tcp://127.0.0.1:26657", CORSAllowedOrigins: []string{}, CORSAllowedMethods: []string{http.MethodHead, http.MethodGet, http.MethodPost}, CORSAllowedHeaders: []string{"Origin", "Accept", "Content-Type", "X-Requested-With", "X-Server-Time"}, GRPCListenAddress: "", GRPCMaxOpenConnections: 900, - StationType: "tcp", Unsafe: false, MaxOpenConnections: 900, diff --git a/node/node.go b/node/node.go index 0c1f0fa..cff6acd 100644 --- a/node/node.go +++ b/node/node.go @@ -272,6 +272,7 @@ func createAndStartIndexerService( dbProvider DBProvider, eventBus *types.EventBus, logger log.Logger, + stationType string, ) (*txindex.IndexerService, txindex.TxIndexer, indexer.BlockIndexer, error) { var ( txIndexer txindex.TxIndexer @@ -304,7 +305,7 @@ func createAndStartIndexerService( blockIndexer = &blockidxnull.BlockerIndexer{} } - indexerService := txindex.NewIndexerService(txIndexer, blockIndexer, eventBus, false) + indexerService := txindex.NewIndexerService(txIndexer, blockIndexer, eventBus, stationType, false) indexerService.SetLogger(logger.With("module", "txindex")) if err := indexerService.Start(); err != nil { @@ -744,8 +745,11 @@ func NewNode(config *cfg.Config, return nil, err } + // tracks type + stationType := config.RPC.TrackStationType // evm / cosmwasm / svm + indexerService, txIndexer, blockIndexer, err := createAndStartIndexerService(config, - genDoc.ChainID, dbProvider, eventBus, logger) + genDoc.ChainID, dbProvider, eventBus, logger, stationType) if err != nil { return nil, err } diff --git a/rpc/core/tracks.go b/rpc/core/tracks.go index 9ed0cf1..e6eff33 100644 --- a/rpc/core/tracks.go +++ b/rpc/core/tracks.go @@ -2,9 +2,10 @@ package core import ( "encoding/json" + "strconv" + rpctypes "github.com/airchains-network/tracksbft/rpc/jsonrpc/types" tracksTypes "github.com/airchains-network/tracksbft/types/tracks" - "strconv" ) func TracksGetPodCount(_ *rpctypes.Context) (int, error) { diff --git a/state/indexer/block/kv/util.go b/state/indexer/block/kv/util.go index 7b55831..140d091 100644 --- a/state/indexer/block/kv/util.go +++ b/state/indexer/block/kv/util.go @@ -3,12 +3,13 @@ package kv import ( "encoding/binary" "fmt" + "math/big" + "strconv" + "github.com/airchains-network/tracksbft/libs/pubsub/query" "github.com/airchains-network/tracksbft/state/indexer" "github.com/airchains-network/tracksbft/types" "github.com/google/orderedcode" - "math/big" - "strconv" ) type HeightInfo struct { diff --git a/state/indexer/sink/psql/backport.go b/state/indexer/sink/psql/backport.go index 4f998ee..6c3217f 100644 --- a/state/indexer/sink/psql/backport.go +++ b/state/indexer/sink/psql/backport.go @@ -92,7 +92,7 @@ func (b2 BackportTxIndexer) GetbytedataFortracks(hash []byte) ([]byte, error) { panic("implement me") } -func (b2 BackportTxIndexer) AddPod(b *txindex.Batch) error { +func (b2 BackportTxIndexer) AddPod(b *txindex.Batch, stationType string) error { //TODO implement me panic("implement me") } diff --git a/state/txindex/indexer.go b/state/txindex/indexer.go index 2536981..0937825 100644 --- a/state/txindex/indexer.go +++ b/state/txindex/indexer.go @@ -14,7 +14,7 @@ import ( // TxIndexer interface defines methods to index and search transactions. type TxIndexer interface { - AddPod(b *Batch) error + AddPod(b *Batch, stationType string) error AddBatch(b *Batch) error GetbytedataFortracks(hash []byte) ([]byte, error) Index(result *abci.TxResult) error diff --git a/state/txindex/indexer_service.go b/state/txindex/indexer_service.go index 73adb36..3ce4774 100644 --- a/state/txindex/indexer_service.go +++ b/state/txindex/indexer_service.go @@ -25,14 +25,19 @@ type IndexerService struct { terminateOnError bool } +var tracksStationType string + // NewIndexerService returns a new service instance. func NewIndexerService( txIdxr TxIndexer, blockIdxr indexer.BlockIndexer, eventBus *types.EventBus, + stationType string, terminateOnError bool, ) *IndexerService { + tracksStationType = stationType + is := &IndexerService{txIdxr: txIdxr, blockIdxr: blockIdxr, eventBus: eventBus, terminateOnError: terminateOnError} is.BaseService = *service.NewBaseService(nil, "IndexerService", is) return is @@ -57,6 +62,8 @@ func (is *IndexerService) OnStart() error { return err } + is.Logger.Info("tracks pods are enabled", "tracksStationType", tracksStationType) + go func() { for { msg := <-blockHeadersSub.Out() @@ -111,7 +118,7 @@ func (is *IndexerService) OnStart() error { } // index pods in database - if err = is.txIdxr.AddPod(batch); err != nil { + if err = is.txIdxr.AddPod(batch, tracksStationType); err != nil { is.Logger.Error("failed to index block txs", "height", height, "err", err) if is.terminateOnError { if err := is.Stop(); err != nil { diff --git a/state/txindex/kv/getBalance.go b/state/txindex/kv/evmGetBalance.go similarity index 93% rename from state/txindex/kv/getBalance.go rename to state/txindex/kv/evmGetBalance.go index 7410ee3..5dee3d3 100644 --- a/state/txindex/kv/getBalance.go +++ b/state/txindex/kv/evmGetBalance.go @@ -21,7 +21,8 @@ func init() { log.Fatalf("Failed to connect to the Ethereum client: %v", err) } } -func getBalanceAtHeight(address string, height int64) (string, error) { + +func GetBalanceAtHeight(address string, height int64) (string, error) { account := common.HexToAddress(address) heightBigInt := big.NewInt(0).SetInt64(height) // *big.Int representation diff --git a/state/txindex/kv/storePod.go b/state/txindex/kv/evmStorePod.go similarity index 97% rename from state/txindex/kv/storePod.go rename to state/txindex/kv/evmStorePod.go index e3d46f3..fa4d23c 100644 --- a/state/txindex/kv/storePod.go +++ b/state/txindex/kv/evmStorePod.go @@ -3,10 +3,11 @@ package kv import ( "encoding/json" "fmt" + "strconv" + abci "github.com/airchains-network/tracksbft/abci/types" txindex "github.com/airchains-network/tracksbft/state/txindex" tracksTypes "github.com/airchains-network/tracksbft/types/tracks" - "strconv" ) func extractAttribute(attributes []abci.EventAttribute, key string) string { @@ -98,13 +99,13 @@ func StorePod(txi *TxIndex, b *txindex.Batch) error { } previousBlockHeight := result.Height - 1 - fromBalance, err = getBalanceAtHeight(sender, previousBlockHeight) + fromBalance, err = GetBalanceAtHeight(sender, previousBlockHeight) if err != nil { fmt.Println("Error checking sender balance:", err) return err } - toBalance, err = getBalanceAtHeight(recipient, previousBlockHeight) + toBalance, err = GetBalanceAtHeight(recipient, previousBlockHeight) if err != nil { fmt.Println("Error checking recipient balance:", err) return err diff --git a/state/txindex/kv/tracksTxUtils.go b/state/txindex/kv/evmUtils.go similarity index 100% rename from state/txindex/kv/tracksTxUtils.go rename to state/txindex/kv/evmUtils.go diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index 48f5adb..994442a 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -118,26 +118,28 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error { return storeBatch.WriteSync() } -func (txi *TxIndex) AddPod(b *txindex.Batch) error { +func (txi *TxIndex) AddPod(b *txindex.Batch, stationType string) error { - // initiate all databases required to make pods if its the first time - byteRes, err := txi.store.Get([]byte("countTxs")) - if err != nil { - return err - } - - if byteRes == nil { - err = InitiateDatabaseForPods(txi) + if stationType == "evm" { + // initiate all databases required to make pods if its the first time + byteRes, err := txi.store.Get([]byte("countTxs")) if err != nil { return err } - } - // store pod in db - err = StorePod(txi, b) // , client, registry, account) - if err != nil { - fmt.Println(err) - return err + if byteRes == nil { + err = InitiateDatabaseForPods(txi) + if err != nil { + return err + } + } + + // store pod in db + err = StorePod(txi, b) // , client, registry, account) + if err != nil { + fmt.Println(err) + return err + } } return nil diff --git a/state/txindex/null/null.go b/state/txindex/null/null.go index 19c7530..6166fe4 100644 --- a/state/txindex/null/null.go +++ b/state/txindex/null/null.go @@ -32,7 +32,7 @@ func (txi *TxIndex) Index(result *abci.TxResult) error { func (txi *TxIndex) Search(ctx context.Context, q *query.Query) ([]*abci.TxResult, error) { return []*abci.TxResult{}, nil } -func (txi *TxIndex) AddPod(b *txindex.Batch) error { // , client cosmosclient.Client, registry cosmosaccount.Registry, account cosmosaccount.Account +func (txi *TxIndex) AddPod(b *txindex.Batch, stationType string) error { // , client cosmosclient.Client, registry cosmosaccount.Registry, account cosmosaccount.Account //TODO implement me panic("implement me") } diff --git a/test/e2e/generator/generate.go b/test/e2e/generator/generate.go index d027fb5..56afbf0 100644 --- a/test/e2e/generator/generate.go +++ b/test/e2e/generator/generate.go @@ -8,8 +8,10 @@ import ( "strconv" "strings" + "github.com/Masterminds/semver" e2e "github.com/airchains-network/tracksbft/test/e2e/pkg" "github.com/airchains-network/tracksbft/version" + "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing/object" )