Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add file-based transaction indexing #546

Merged
merged 38 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
38fb2f8
Add base tx indexer logic
zivkovicmilos Feb 27, 2023
ed13499
Add file indexer
zivkovicmilos Feb 27, 2023
08360c2
Simplify types
zivkovicmilos Feb 27, 2023
367b20d
Add unit test for file tx indexer
zivkovicmilos Feb 27, 2023
0ce73e5
Add unit test for indexer config
zivkovicmilos Feb 27, 2023
994de46
Add unit test for the indexer service
zivkovicmilos Feb 28, 2023
6d21b54
Add additional docs
zivkovicmilos Feb 28, 2023
ccdd6fd
Fix help output
zivkovicmilos Feb 28, 2023
5c82d82
Update node info for the indexer
zivkovicmilos Feb 28, 2023
e612c06
Add flush operation to indexer
zivkovicmilos Feb 28, 2023
b824a60
Add indexer config to test files
zivkovicmilos Feb 28, 2023
2b9d8f3
Add constant default value for indexer type
zivkovicmilos Feb 28, 2023
7387d4a
Change binding to work on Macs for some reason
zivkovicmilos Mar 2, 2023
8c2e4b4
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Mar 2, 2023
c0da941
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos May 15, 2023
90e69c2
Remove leftover .gno files
zivkovicmilos May 15, 2023
9df0ce3
Run gofumpt
zivkovicmilos May 15, 2023
c09a831
Simplify indexer type listing
zivkovicmilos May 16, 2023
dee7806
Add error logging for group methods
zivkovicmilos May 16, 2023
8f13f4e
Add constants for indexer status
zivkovicmilos May 16, 2023
2c5aaa6
Change import alias
zivkovicmilos May 16, 2023
86c11c9
Standardize error logging in the indexer service
zivkovicmilos May 16, 2023
7f81211
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Jul 4, 2023
443953d
Rename indexer -> event store
zivkovicmilos Jul 7, 2023
16f07c8
Rename event switch reference
zivkovicmilos Jul 7, 2023
b7c1dca
Revert error assignment
zivkovicmilos Jul 7, 2023
20e9a5c
Move event store status to the event store package
zivkovicmilos Jul 7, 2023
c865287
Rename event store interface method
zivkovicmilos Jul 7, 2023
10c2483
Rename event store files
zivkovicmilos Jul 7, 2023
f1567f4
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Jul 13, 2023
2f9cf60
Resolve renamed cfg reference
zivkovicmilos Jul 13, 2023
6deaa60
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Jul 27, 2023
b562b19
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Aug 3, 2023
520c153
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Aug 10, 2023
80c8c10
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Aug 17, 2023
3204a38
Resolve typo in help output
zivkovicmilos Aug 17, 2023
b9b16d0
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Aug 31, 2023
d43a83f
Merge branch 'master' into feature/simple-tx-indexing
zivkovicmilos Oct 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions gno.land/cmd/gnoland/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"path/filepath"
Expand All @@ -16,6 +17,9 @@ import (
"github.com/gnolang/gno/tm2/pkg/bft/config"
"github.com/gnolang/gno/tm2/pkg/bft/node"
"github.com/gnolang/gno/tm2/pkg/bft/privval"
"github.com/gnolang/gno/tm2/pkg/bft/state/eventstore/file"
"github.com/gnolang/gno/tm2/pkg/bft/state/eventstore/null"
eventstorecfg "github.com/gnolang/gno/tm2/pkg/bft/state/eventstore/types"
bft "github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/crypto"
Expand All @@ -35,6 +39,9 @@ type startCfg struct {
rootDir string
genesisMaxVMCycles int64
config string

txEventStoreType string
txEventStorePath string
}

func newStartCmd(io *commands.IO) *commands.Command {
Expand Down Expand Up @@ -116,6 +123,29 @@ func (c *startCfg) RegisterFlags(fs *flag.FlagSet) {
"",
"config file (optional)",
)

fs.StringVar(
&c.txEventStoreType,
"tx-event-store-type",
null.EventStoreType,
fmt.Sprintf(
"type of transaction event store [%s]",
strings.Join(
[]string{
null.EventStoreType,
file.EventStoreType,
},
", ",
),
),
)

fs.StringVar(
&c.txEventStorePath,
"tx-event-store-path",
"",
fmt.Sprintf("path for the file tx event store (required if event store is '%s')", file.EventStoreType),
)
}

func execStart(c *startCfg, args []string, io *commands.IO) error {
Expand Down Expand Up @@ -145,6 +175,14 @@ func execStart(c *startCfg, args []string, io *commands.IO) error {
writeGenesisFile(genDoc, genesisFilePath)
}

// Initialize the indexer config
txEventStoreCfg, err := getTxEventStoreConfig(c)
if err != nil {
return fmt.Errorf("unable to parse indexer config, %w", err)
}

cfg.TxEventStore = txEventStoreCfg

// create application and node.
gnoApp, err := gnoland.NewApp(rootDir, c.skipFailingGenesisTxs, logger, c.genesisMaxVMCycles)
if err != nil {
Expand Down Expand Up @@ -180,6 +218,30 @@ func execStart(c *startCfg, args []string, io *commands.IO) error {
select {} // run forever
}

// getTxEventStoreConfig constructs an event store config from provided user options
func getTxEventStoreConfig(c *startCfg) (*eventstorecfg.Config, error) {
var cfg *eventstorecfg.Config

switch c.txEventStoreType {
case file.EventStoreType:
if c.txEventStorePath == "" {
return nil, errors.New("unspecified file transaction indexer path")
}

// Fill out the configuration
cfg = &eventstorecfg.Config{
EventStoreType: file.EventStoreType,
Params: map[string]any{
file.Path: c.txEventStorePath,
},
}
default:
cfg = eventstorecfg.DefaultEventStoreConfig()
}

return cfg, nil
}

// Makes a local test genesis doc with local privValidator.
func makeGenesisDoc(
pvPub crypto.PubKey,
Expand Down
21 changes: 17 additions & 4 deletions tm2/pkg/autofile/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ func (g *Group) OnStart() error {
// OnStop implements service.Service by stopping the goroutine described above.
// NOTE: g.Head must be closed separately using Close.
func (g *Group) OnStop() {
g.FlushAndSync()
if err := g.FlushAndSync(); err != nil {
zivkovicmilos marked this conversation as resolved.
Show resolved Hide resolved
g.Logger.Error(
fmt.Sprintf("unable to gracefully flush data, %s", err.Error()),
)
}
}

// Wait blocks until all internal goroutines are finished. Supposed to be
Expand All @@ -136,11 +140,20 @@ func (g *Group) Wait() {

// Close closes the head file. The group must be stopped by this moment.
func (g *Group) Close() {
g.FlushAndSync()
if err := g.FlushAndSync(); err != nil {
g.Logger.Error(
fmt.Sprintf("unable to gracefully flush data, %s", err.Error()),
)
}

g.mtx.Lock()
_ = g.Head.Close()
g.mtx.Unlock()
defer g.mtx.Unlock()

if err := g.Head.Close(); err != nil {
g.Logger.Error(
fmt.Sprintf("unable to gracefully close group head, %s", err.Error()),
)
}
}

// HeadSizeLimit returns the current head size limit.
Expand Down
34 changes: 19 additions & 15 deletions tm2/pkg/bft/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
cns "github.com/gnolang/gno/tm2/pkg/bft/consensus/config"
mem "github.com/gnolang/gno/tm2/pkg/bft/mempool/config"
rpc "github.com/gnolang/gno/tm2/pkg/bft/rpc/config"
eventstore "github.com/gnolang/gno/tm2/pkg/bft/state/eventstore/types"
"github.com/gnolang/gno/tm2/pkg/errors"
osm "github.com/gnolang/gno/tm2/pkg/os"
p2p "github.com/gnolang/gno/tm2/pkg/p2p/config"
Expand All @@ -20,20 +21,22 @@ type Config struct {
BaseConfig `toml:",squash"`

// Options for services
RPC *rpc.RPCConfig `toml:"rpc"`
P2P *p2p.P2PConfig `toml:"p2p"`
Mempool *mem.MempoolConfig `toml:"mempool"`
Consensus *cns.ConsensusConfig `toml:"consensus"`
RPC *rpc.RPCConfig `toml:"rpc"`
P2P *p2p.P2PConfig `toml:"p2p"`
Mempool *mem.MempoolConfig `toml:"mempool"`
Consensus *cns.ConsensusConfig `toml:"consensus"`
TxEventStore *eventstore.Config `toml:"tx_event_store"`
}

// DefaultConfig returns a default configuration for a Tendermint node
func DefaultConfig() *Config {
return &Config{
BaseConfig: DefaultBaseConfig(),
RPC: rpc.DefaultRPCConfig(),
P2P: p2p.DefaultP2PConfig(),
Mempool: mem.DefaultMempoolConfig(),
Consensus: cns.DefaultConsensusConfig(),
BaseConfig: DefaultBaseConfig(),
RPC: rpc.DefaultRPCConfig(),
P2P: p2p.DefaultP2PConfig(),
Mempool: mem.DefaultMempoolConfig(),
Consensus: cns.DefaultConsensusConfig(),
TxEventStore: eventstore.DefaultEventStoreConfig(),
}
}

Expand Down Expand Up @@ -68,11 +71,12 @@ func LoadOrMakeConfigWithOptions(root string, options ConfigOptions) (cfg *Confi
// TestConfig returns a configuration that can be used for testing
func TestConfig() *Config {
return &Config{
BaseConfig: TestBaseConfig(),
RPC: rpc.TestRPCConfig(),
P2P: p2p.TestP2PConfig(),
Mempool: mem.TestMempoolConfig(),
Consensus: cns.TestConsensusConfig(),
BaseConfig: TestBaseConfig(),
RPC: rpc.TestRPCConfig(),
P2P: p2p.TestP2PConfig(),
Mempool: mem.TestMempoolConfig(),
Consensus: cns.TestConsensusConfig(),
TxEventStore: eventstore.DefaultEventStoreConfig(),
}
}

Expand Down Expand Up @@ -121,7 +125,7 @@ func (cfg *Config) ValidateBasic() error {
return nil
}

//-----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// BaseConfig

const (
Expand Down
Loading
Loading