Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ linters:
- errorlint
- errcheck
- gofmt
- goimports
- gci
- gosec
- gosimple
- govet
Expand Down Expand Up @@ -44,6 +44,10 @@ linters-settings:
- name: exported
arguments:
- disableStutteringCheck

goimports:
local-prefixes: github.com/rollkit
gci:
custom-order: true
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(github.com/rollkit)
- prefix(github.com/rollkit/rollkit)
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ lint: vet
.PHONY: lint

## fmt: Run fixes for linters.
fmt:
@echo "--> Formatting markdownlint"
@markdownlint --config .markdownlint.yaml --ignore './cmd/rollkit/docs/*.md' '**/*.md' -f
lint-fix:
@echo "--> Formatting go"
@golangci-lint run --fix
@echo "--> Formatting markdownlint"
@markdownlint --config .markdownlint.yaml --ignore './cmd/rollkit/docs/*.md' '**/*.md' -f
.PHONY: fmt

## vet: Run go vet
Expand All @@ -74,7 +74,7 @@ vet:
## test: Running unit tests
test: vet
@echo "--> Running unit tests"
@go test -v -race -covermode=atomic -coverprofile=coverage.txt $(pkgs) -run $(run) -count=$(count)
@go test -race -covermode=atomic -coverprofile=coverage.txt $(pkgs) -run $(run) -count=$(count)
.PHONY: test

## proto-gen: Generate protobuf files. Requires docker.
Expand Down
21 changes: 10 additions & 11 deletions block/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ import (
"sync/atomic"
"time"

cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmstate "github.com/cometbft/cometbft/proto/tendermint/state"

secp256k1 "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
goheaderstore "github.com/celestiaorg/go-header/store"
abci "github.com/cometbft/cometbft/abci/types"
cmcrypto "github.com/cometbft/cometbft/crypto"
cmbytes "github.com/cometbft/cometbft/libs/bytes"
cmstate "github.com/cometbft/cometbft/proto/tendermint/state"
cmproto "github.com/cometbft/cometbft/proto/tendermint/types"
cmtypes "github.com/cometbft/cometbft/types"
ds "github.com/ipfs/go-datastore"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/crypto/pb"

goheaderstore "github.com/celestiaorg/go-header/store"

"github.com/rollkit/go-execution"
execTypes "github.com/rollkit/go-execution/types"
"github.com/rollkit/go-sequencing"
"github.com/rollkit/go-sequencing/proxy/grpc"

"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/da"
"github.com/rollkit/rollkit/store"
Expand Down Expand Up @@ -177,7 +176,7 @@ type RollkitGenesis struct {
// getInitialState tries to load lastState from Store, and if it's not available it reads GenesisDoc.
func getInitialState(ctx context.Context, genesis *RollkitGenesis, store store.Store, exec execution.Executor, logger log.Logger) (types.State, error) {
// Load the state from store.
s, err := store.GetState(context.Background())
s, err := store.GetState(ctx)

if errors.Is(err, ds.ErrNotFound) {
logger.Info("No state found in store, initializing new state")
Expand Down Expand Up @@ -259,7 +258,7 @@ func NewManager(
return nil, err
}
//set block height in store
store.SetHeight(context.Background(), s.LastBlockHeight)
store.SetHeight(ctx, s.LastBlockHeight)

if s.DAHeight < conf.DAStartHeight {
s.DAHeight = conf.DAStartHeight
Expand Down Expand Up @@ -287,7 +286,7 @@ func NewManager(

//proposerAddress := s.Validators.Proposer.Address.Bytes()

maxBlobSize, err := dalc.DA.MaxBlobSize(context.Background())
maxBlobSize, err := dalc.DA.MaxBlobSize(ctx)
if err != nil {
return nil, err
}
Expand All @@ -307,7 +306,7 @@ func NewManager(
}

// If lastBatchHash is not set, retrieve the last batch hash from store
lastBatchHash, err := store.GetMetadata(context.Background(), LastBatchHashKey)
lastBatchHash, err := store.GetMetadata(ctx, LastBatchHashKey)
if err != nil {
logger.Error("error while retrieving last batch hash", "error", err)
}
Expand Down Expand Up @@ -343,7 +342,7 @@ func NewManager(
bq: NewBatchQueue(),
exec: exec,
}
agg.init(context.Background())
agg.init(ctx)
return agg, nil
}

Expand Down Expand Up @@ -675,7 +674,7 @@ func (m *Manager) handleEmptyDataHash(ctx context.Context, header *types.Header)
//
// SyncLoop processes headers gossiped in P2P network to know what's the latest block height,
// block data is retrieved from DA layer.
func (m *Manager) SyncLoop(ctx context.Context, cancel context.CancelFunc) {
func (m *Manager) SyncLoop(ctx context.Context) {
daTicker := time.NewTicker(m.conf.DABlockTime)
defer daTicker.Stop()
blockTicker := time.NewTicker(m.conf.BlockTime)
Expand Down
11 changes: 5 additions & 6 deletions block/sync_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import (
"fmt"
"strings"

"github.com/cometbft/cometbft/libs/log"
"cosmossdk.io/log"
"github.com/celestiaorg/go-header"
goheaderp2p "github.com/celestiaorg/go-header/p2p"
goheaderstore "github.com/celestiaorg/go-header/store"
goheadersync "github.com/celestiaorg/go-header/sync"
cmtypes "github.com/cometbft/cometbft/types"
ds "github.com/ipfs/go-datastore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand All @@ -16,11 +20,6 @@ import (
"github.com/libp2p/go-libp2p/p2p/net/conngater"
"github.com/multiformats/go-multiaddr"

"github.com/celestiaorg/go-header"
goheaderp2p "github.com/celestiaorg/go-header/p2p"
goheaderstore "github.com/celestiaorg/go-header/store"
goheadersync "github.com/celestiaorg/go-header/sync"

"github.com/rollkit/rollkit/config"
"github.com/rollkit/rollkit/p2p"
"github.com/rollkit/rollkit/types"
Expand Down
4 changes: 2 additions & 2 deletions cmd/rollkit/commands/intercept.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"path/filepath"
"strings"

cometos "github.com/cometbft/cometbft/libs/os"
"github.com/spf13/cobra"
"google.golang.org/grpc"

cometos "github.com/cometbft/cometbft/libs/os"

proxy "github.com/rollkit/go-da/proxy/jsonrpc"

rollconf "github.com/rollkit/rollkit/config"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/rollkit/commands/intercept_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"os"
"testing"

rollconf "github.com/rollkit/rollkit/config"

"github.com/spf13/cobra"

rollconf "github.com/rollkit/rollkit/config"
)

func TestInterceptCommand(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/rollkit/commands/rebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package commands
import (
"log"

rollconf "github.com/rollkit/rollkit/config"

"github.com/spf13/cobra"

rollconf "github.com/rollkit/rollkit/config"
)

// RebuildCmd is a command to rebuild rollup entrypoint
Expand Down
3 changes: 1 addition & 2 deletions cmd/rollkit/commands/root.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package commands

import (
"github.com/spf13/cobra"

cometconfig "github.com/cometbft/cometbft/config"
"github.com/spf13/cobra"
)

func init() {
Expand Down
54 changes: 27 additions & 27 deletions cmd/rollkit/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,34 @@ import (
"syscall"
"time"

"cosmossdk.io/log"
cmtcmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
cometconf "github.com/cometbft/cometbft/config"
cometcli "github.com/cometbft/cometbft/libs/cli"
cometflags "github.com/cometbft/cometbft/libs/cli/flags"
cometlog "github.com/cometbft/cometbft/libs/log"
cometos "github.com/cometbft/cometbft/libs/os"
cometnode "github.com/cometbft/cometbft/node"
cometp2p "github.com/cometbft/cometbft/p2p"
cometprivval "github.com/cometbft/cometbft/privval"
comettypes "github.com/cometbft/cometbft/types"
comettime "github.com/cometbft/cometbft/types/time"
"github.com/mitchellh/mapstructure"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"google.golang.org/grpc"

"github.com/rollkit/go-da"
proxy "github.com/rollkit/go-da/proxy/jsonrpc"
goDATest "github.com/rollkit/go-da/test"
execGRPC "github.com/rollkit/go-execution/proxy/grpc"
execTest "github.com/rollkit/go-execution/test"
execTypes "github.com/rollkit/go-execution/types"
pb "github.com/rollkit/go-execution/types/pb/execution"
seqGRPC "github.com/rollkit/go-sequencing/proxy/grpc"
seqTest "github.com/rollkit/go-sequencing/test"

"github.com/spf13/cobra"
"github.com/spf13/viper"

rollconf "github.com/rollkit/rollkit/config"
rollnode "github.com/rollkit/rollkit/node"
rolltypes "github.com/rollkit/rollkit/types"

execGRPC "github.com/rollkit/go-execution/proxy/grpc"
execTest "github.com/rollkit/go-execution/test"
execTypes "github.com/rollkit/go-execution/types"
pb "github.com/rollkit/go-execution/types/pb/execution"
)

var (
Expand All @@ -52,7 +49,7 @@ var (
nodeConfig = rollconf.DefaultNodeConfig

// initialize the logger with the cometBFT defaults
logger = cometlog.NewTMLogger(cometlog.NewSyncWriter(os.Stdout))
logger = log.NewLogger(os.Stdout)

errDAServerAlreadyRunning = errors.New("DA server already running")
errSequencerAlreadyRunning = errors.New("sequencer already running")
Expand All @@ -78,20 +75,20 @@ func NewRunNodeCmd() *cobra.Command {
}

// Update log format if the flag is set
if config.LogFormat == cometconf.LogFormatJSON {
logger = cometlog.NewTMJSONLogger(cometlog.NewSyncWriter(os.Stdout))
}
// if config.LogFormat == cometconf.LogFormatJSON {
// logger = cometlog.NewTMJSONLogger(cometlog.NewSyncWriter(os.Stdout))
// }

// Parse the log level
logger, err = cometflags.ParseLogLevel(config.LogLevel, logger, cometconf.DefaultLogLevel)
if err != nil {
return err
}
// // Parse the log level
// logger, err = cometflags.ParseLogLevel(config.LogLevel, logger, cometconf.DefaultLogLevel)
// if err != nil {
// return err
// }

// Add tracing to the logger if the flag is set
if viper.GetBool(cometcli.TraceFlag) {
logger = cometlog.NewTracingLogger(logger)
}
// // Add tracing to the logger if the flag is set
// if viper.GetBool(cometcli.TraceFlag) {
// logger = cometlog.NewTracingLogger(logger)
// }

logger = logger.With("module", "main")

Expand Down Expand Up @@ -192,9 +189,12 @@ func NewRunNodeCmd() *cobra.Command {
config.ProxyApp = "noop"
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// create the rollkit node
rollnode, err := rollnode.NewNode(
context.Background(),
ctx,
nodeConfig,
p2pKey,
signingKey,
Expand All @@ -207,7 +207,7 @@ func NewRunNodeCmd() *cobra.Command {
}

// Start the node
if err := rollnode.Start(); err != nil {
if err := rollnode.Start(ctx); err != nil {
return fmt.Errorf("failed to start node: %w", err)
}

Expand All @@ -217,7 +217,7 @@ func NewRunNodeCmd() *cobra.Command {
// Stop upon receiving SIGTERM or CTRL-C.
cometos.TrapSignal(logger, func() {
if rollnode.IsRunning() {
if err := rollnode.Stop(); err != nil {
if err := rollnode.Stop(ctx); err != nil {
logger.Error("unable to stop the node", "error", err)
}
}
Expand All @@ -239,7 +239,7 @@ func NewRunNodeCmd() *cobra.Command {
return fmt.Errorf("node is not running")
}

return rollnode.Stop()
return rollnode.Stop(ctx)
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/rollkit/commands/run_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/rollkit/go-da"
proxy "github.com/rollkit/go-da/proxy/jsonrpc"

rollconf "github.com/rollkit/rollkit/config"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/rollkit/commands/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"os"

rollconf "github.com/rollkit/rollkit/config"

"github.com/spf13/cobra"

rollconf "github.com/rollkit/rollkit/config"
)

// NewTomlCmd creates a new cobra command group for TOML file operations.
Expand Down
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"time"

cmcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down
1 change: 0 additions & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

cmcfg "github.com/cometbft/cometbft/config"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
Expand Down
1 change: 1 addition & 0 deletions da/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/gogo/protobuf/proto"

goDA "github.com/rollkit/go-da"

"github.com/rollkit/rollkit/third_party/log"
"github.com/rollkit/rollkit/types"
pb "github.com/rollkit/rollkit/types/pb/rollkit"
Expand Down
1 change: 1 addition & 0 deletions da/da_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
proxygrpc "github.com/rollkit/go-da/proxy/grpc"
proxyjsonrpc "github.com/rollkit/go-da/proxy/jsonrpc"
goDATest "github.com/rollkit/go-da/test"

testServer "github.com/rollkit/rollkit/test/server"
"github.com/rollkit/rollkit/types"
)
Expand Down
Loading