Skip to content

Commit

Permalink
Introduced new field TrackStationType in node config.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aakash4dev committed Jun 25, 2024
1 parent d2de20a commit fc8535d
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 45 deletions.
22 changes: 11 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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).

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
go mod edit -replace github.com/tendermint/tendermint=github.com/cometbft/[email protected]
```

We make use of the original module URL in order to minimize the impact of
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 6 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion rpc/core/tracks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions state/indexer/block/kv/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion state/indexer/sink/psql/backport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion state/txindex/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion state/txindex/indexer_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.
32 changes: 17 additions & 15 deletions state/txindex/kv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion state/txindex/null/null.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down

0 comments on commit fc8535d

Please sign in to comment.