Skip to content

Commit

Permalink
chore: reflect testing and code review
Browse files Browse the repository at this point in the history
  • Loading branch information
kangsorang committed Nov 27, 2023
1 parent 1fac96d commit 561a3c7
Show file tree
Hide file tree
Showing 148 changed files with 675 additions and 1,241 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Go 1.19
- name: Setup Go 1.21
uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.21'
- run: go mod download

- name: Setup Node.js 16.x
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
with:
fetch-depth: 0

- name: Setup Go 1.19
- name: Setup Go 1.21
uses: actions/setup-go@v4
with:
go-version: '1.19'
go-version: '1.21'
- run: go mod download

- name: Setup Node.js 16.x
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ COPY ./Makefile /app/Makefile
COPY ./op-node /app/op-node
COPY ./op-chain-ops /app/op-chain-ops
COPY ./op-service /app/op-service
#COPY ./op-signer /app/op-signer
COPY ./op-batcher /app/op-batcher
COPY ./op-bindings /app/op-bindings
COPY ./components /app/components
COPY ./utils /app/utils
COPY ./kroma-validator /app/kroma-validator

COPY ./.git /app/.git
WORKDIR /app
Expand Down
42 changes: 0 additions & 42 deletions FORK.md

This file was deleted.

7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build:
GO111MODULE=on go build -v $(LD_FLAGS) -o bin/kroma-node ./op-node/cmd/main.go
GO111MODULE=on go build -v $(LD_FLAGS) -o bin/kroma-stateviz ./op-node/cmd/stateviz/main.go
GO111MODULE=on go build -v $(LD_FLAGS) -o bin/kroma-batcher ./op-batcher/cmd/main.go
GO111MODULE=on go build -v $(LD_FLAGS) -o bin/kroma-validator ./components/validator/cmd/main.go
GO111MODULE=on go build -v $(LD_FLAGS) -o bin/kroma-validator ./kroma-validator/cmd/main.go
.PHONY: build

clean:
Expand All @@ -20,8 +20,9 @@ test:
go test ./op-bindings/...
go test ./op-batcher/...
go test ./op-node/...
go test ./components/...
go test ./utils/...
go test ./op-service/...
go test ./op-chain-ops/...
go test ./kroma-validator/...
go test ./op-e2e/... -timeout 30m # requires a minimum of 30min in a CI
yarn test
.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ require (

replace github.com/ethereum-optimism/optimism v1.2.0 => ./

replace github.com/ethereum/go-ethereum v1.13.1 => github.com/kroma-network/go-ethereum v0.1.1-0.20231115080421-4806bf9b7ddf // https://github.com/kroma-network/go-ethereum/pull/57/commits
replace github.com/ethereum/go-ethereum v1.13.1 => github.com/kroma-network/go-ethereum v0.1.1-0.20231117080707-add3e71070bd
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kroma-network/go-ethereum v0.1.1-0.20231115080421-4806bf9b7ddf h1:GHtJvvUWpgm5r/mkIDo3rNCUCG+/CuM0xfcUo1tmp98=
github.com/kroma-network/go-ethereum v0.1.1-0.20231115080421-4806bf9b7ddf/go.mod h1:F4IxiqhpUiwffnQQ+iHQU0Hh+c8Wdsa2h1lSoFyVRM0=
github.com/kroma-network/go-ethereum v0.1.1-0.20231117080707-add3e71070bd h1:l6EWu3BuWKSO7LkryajbgMfUXjn1RhCctbq+t5bb6t8=
github.com/kroma-network/go-ethereum v0.1.1-0.20231117080707-add3e71070bd/go.mod h1:F4IxiqhpUiwffnQQ+iHQU0Hh+c8Wdsa2h1lSoFyVRM0=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84 h1:VpLCQx+tFV6Nk0hbs3Noyxma/q9wIDdyacKpGQWUMI8=
github.com/kroma-network/zktrie v0.5.1-0.20230420142222-950ce7a8ce84/go.mod h1:w54LrYo5rJEV503BgMPRNONsLTOEQv5V87q+uYaw9sM=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import (

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/optsutils"
"github.com/ethereum-optimism/optimism/op-service/watcher"
chal "github.com/kroma-network/kroma/components/validator/challenge"
"github.com/kroma-network/kroma/components/validator/metrics"
"github.com/kroma-network/kroma/utils"
chal "github.com/kroma-network/kroma/kroma-validator/challenge"
"github.com/kroma-network/kroma/kroma-validator/metrics"
)

var deletedOutputRoot = [32]byte{}
Expand Down Expand Up @@ -112,23 +112,23 @@ func (c *Challenger) InitConfig(ctx context.Context) error {
err := contractWatcher.WatchUpgraded(c.cfg.L2OutputOracleAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
submissionInterval, err := c.l2ooContract.SUBMISSIONINTERVAL(utils.NewSimpleCallOpts(cCtx))
submissionInterval, err := c.l2ooContract.SUBMISSIONINTERVAL(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get submission interval: %w", err)
}
c.submissionInterval = submissionInterval

cCtx, cCancel = context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
l2BlockTime, err := c.l2ooContract.L2BLOCKTIME(utils.NewSimpleCallOpts(cCtx))
l2BlockTime, err := c.l2ooContract.L2BLOCKTIME(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get l2 block time: %w", err)
}
c.l2BlockTime = l2BlockTime

cCtx, cCancel = context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
finalizationPeriodSeconds, err := c.l2ooContract.FINALIZATIONPERIODSECONDS(utils.NewSimpleCallOpts(cCtx))
finalizationPeriodSeconds, err := c.l2ooContract.FINALIZATIONPERIODSECONDS(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get finalization period seconds: %w", err)
}
Expand All @@ -143,7 +143,7 @@ func (c *Challenger) InitConfig(ctx context.Context) error {
err = contractWatcher.WatchUpgraded(c.cfg.ValidatorPoolAddr, func() error {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
requiredBondAmount, err := c.valpoolContract.REQUIREDBONDAMOUNT(utils.NewSimpleCallOpts(cCtx))
requiredBondAmount, err := c.valpoolContract.REQUIREDBONDAMOUNT(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get submission interval: %w", err)
}
Expand All @@ -160,7 +160,7 @@ func (c *Challenger) InitConfig(ctx context.Context) error {

// initSub initialize subscriptions
func (c *Challenger) initSub() {
opts := utils.NewSimpleWatchOpts(c.ctx)
opts := optsutils.NewSimpleWatchOpts(c.ctx)

if c.cfg.ChallengerEnabled {
c.l2OutputSubmittedEventChan = make(chan *bindings.L2OutputOracleOutputSubmitted)
Expand Down Expand Up @@ -255,7 +255,7 @@ func (c *Challenger) loop() {
func (c *Challenger) updateCheckpoint() error {
cCtx, cCancel := context.WithTimeout(c.ctx, c.cfg.NetworkTimeout)
defer cCancel()
nextOutputIndex, err := c.l2ooContract.NextOutputIndex(utils.NewSimpleCallOpts(cCtx))
nextOutputIndex, err := c.l2ooContract.NextOutputIndex(optsutils.NewSimpleCallOpts(cCtx))
if err != nil {
return fmt.Errorf("failed to get the latest output index: %w", err)
}
Expand Down Expand Up @@ -602,7 +602,7 @@ func (c *Challenger) submitChallengeTx(tx *types.Transaction) error {
func (c *Challenger) HasEnoughDeposit(ctx context.Context) (bool, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
balance, err := c.valpoolContract.BalanceOf(utils.NewSimpleCallOpts(cCtx), c.cfg.TxManager.From())
balance, err := c.valpoolContract.BalanceOf(optsutils.NewSimpleCallOpts(cCtx), c.cfg.TxManager.From())
if err != nil {
return false, fmt.Errorf("failed to fetch deposit amount: %w", err)
}
Expand All @@ -620,19 +620,19 @@ func (c *Challenger) HasEnoughDeposit(ctx context.Context) (bool, error) {
func (c *Challenger) IsInChallengeCreationPeriod(ctx context.Context, outputIndex *big.Int) (bool, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
return c.colosseumContract.IsInCreationPeriod(utils.NewSimpleCallOpts(cCtx), outputIndex)
return c.colosseumContract.IsInCreationPeriod(optsutils.NewSimpleCallOpts(cCtx), outputIndex)
}

func (c *Challenger) IsOutputFinalized(ctx context.Context, outputIndex *big.Int) (bool, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
return c.l2ooContract.IsFinalized(utils.NewSimpleCallOpts(cCtx), outputIndex)
return c.l2ooContract.IsFinalized(optsutils.NewSimpleCallOpts(cCtx), outputIndex)
}

func (c *Challenger) GetChallenge(ctx context.Context, outputIndex *big.Int, challenger common.Address) (bindings.TypesChallenge, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
return c.colosseumContract.GetChallenge(utils.NewSimpleCallOpts(cCtx), outputIndex, challenger)
return c.colosseumContract.GetChallenge(optsutils.NewSimpleCallOpts(cCtx), outputIndex, challenger)
}

func (c *Challenger) OutputAtBlockSafe(ctx context.Context, blockNumber uint64) (*eth.OutputResponse, error) {
Expand Down Expand Up @@ -698,7 +698,7 @@ type Outputs struct {
func (c *Challenger) OutputsAtIndex(ctx context.Context, outputIndex *big.Int) (*Outputs, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
RemoteOutput, err := c.l2ooContract.GetL2Output(utils.NewSimpleCallOpts(cCtx), outputIndex)
RemoteOutput, err := c.l2ooContract.GetL2Output(optsutils.NewSimpleCallOpts(cCtx), outputIndex)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -755,13 +755,13 @@ func (c *Challenger) isRelatedChallenge(asserter common.Address, challenger comm
func (c *Challenger) GetChallengeStatus(ctx context.Context, outputIndex *big.Int, challenger common.Address) (uint8, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
return c.colosseumContract.GetStatus(utils.NewSimpleCallOpts(cCtx), outputIndex, challenger)
return c.colosseumContract.GetStatus(optsutils.NewSimpleCallOpts(cCtx), outputIndex, challenger)
}

func (c *Challenger) BuildSegments(ctx context.Context, turn uint8, segStart, segSize uint64) (*chal.Segments, error) {
cCtx, cCancel := context.WithTimeout(ctx, c.cfg.NetworkTimeout)
defer cCancel()
sections, err := c.colosseumContract.GetSegmentsLength(utils.NewSimpleCallOpts(cCtx), turn)
sections, err := c.colosseumContract.GetSegmentsLength(optsutils.NewSimpleCallOpts(cCtx), turn)
if err != nil {
return nil, fmt.Errorf("unable to get segments length of turn %d: %w", turn, err)
}
Expand Down Expand Up @@ -814,7 +814,7 @@ func (c *Challenger) CreateChallenge(ctx context.Context, outputRange *OutputRan
return nil, err
}

txOpts := utils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
txOpts := optsutils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
return c.colosseumContract.CreateChallenge(txOpts, outputIndex, l1BlockHash, l1BlockNumber, segments.Hashes)
}

Expand Down Expand Up @@ -843,21 +843,21 @@ func (c *Challenger) Bisect(ctx context.Context, outputIndex *big.Int, challenge
return nil, err
}

txOpts := utils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
txOpts := optsutils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
return c.colosseumContract.Bisect(txOpts, outputIndex, challenger, position, nextSegments.Hashes)
}

func (c *Challenger) ChallengerTimeout(ctx context.Context, outputIndex *big.Int, challenger common.Address) (*types.Transaction, error) {
c.log.Info("crafting challenger timeout tx", "outputIndex", outputIndex, "challenger", challenger)

txOpts := utils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
txOpts := optsutils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
return c.colosseumContract.ChallengerTimeout(txOpts, outputIndex, challenger)
}

func (c *Challenger) CancelChallenge(ctx context.Context, outputIndex *big.Int) (*types.Transaction, error) {
c.log.Info("crafting cancel challenge tx", "outputIndex", outputIndex)

txOpts := utils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
txOpts := optsutils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
return c.colosseumContract.CancelChallenge(txOpts, outputIndex)
}

Expand Down Expand Up @@ -907,7 +907,7 @@ func (c *Challenger) ProveFault(ctx context.Context, outputIndex *big.Int, chall
return nil, fmt.Errorf("failed to fetch proof and pair(fault position blockNumber: %d): %w", targetBlockNumber.Uint64(), err)
}

txOpts := utils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
txOpts := optsutils.NewSimpleTxOpts(ctx, c.cfg.TxManager.From(), c.cfg.TxManager.Signer)
return c.colosseumContract.ProveFault(
txOpts,
outputIndex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/urfave/cli/v2"

"github.com/ethereum-optimism/optimism/op-bindings/bindings"
opservice "github.com/ethereum-optimism/optimism/op-service"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/metrics"
"github.com/kroma-network/kroma/components/validator/flags"
"github.com/kroma-network/kroma/utils"
"github.com/kroma-network/kroma/kroma-validator/flags"
)

func Deposit(ctx *cli.Context) error {
Expand Down Expand Up @@ -80,7 +80,7 @@ func sendTransaction(ctx *cli.Context, txData []byte, txValue uint64) error {
return fmt.Errorf("failed to create tx manager: %w", err)
}

valpoolAddr, err := utils.ParseAddress(ctx.String(flags.ValPoolAddressFlag.Name))
valpoolAddr, err := opservice.ParseAddress(ctx.String(flags.ValPoolAddressFlag.Name))
if err != nil {
return fmt.Errorf("failed to parse ValidatorPool address: %w", err)
}
Expand Down
16 changes: 8 additions & 8 deletions components/validator/cmd/main.go → kroma-validator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/urfave/cli/v2"

klog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/kroma-network/kroma/components/validator"
"github.com/kroma-network/kroma/components/validator/cmd/balance"
"github.com/kroma-network/kroma/components/validator/flags"
"github.com/ethereum-optimism/optimism/op-service/cliapp"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/kroma-network/kroma/kroma-validator"
"github.com/kroma-network/kroma/kroma-validator/cmd/balance"
"github.com/kroma-network/kroma/kroma-validator/flags"
)

var (
Expand All @@ -19,15 +20,14 @@ var (
)

func main() {
klog.SetupDefaults()
oplog.SetupDefaults()

app := cli.NewApp()
app.Flags = flags.Flags
app.Flags = cliapp.ProtectFlags(flags.Flags)
app.Version = fmt.Sprintf("%s-%s", Version, Meta)
app.Name = "kroma-validator"
app.Usage = "L2 Output Submitter and Challenger Service"
app.Description = "Service for generating and submitting L2 output checkpoints to the L2OutputOracle contract as an L2 Output Submitter, " + "detecting and correcting invalid L2 outputs as a Challenger to ensure the integrity of the L2 state."

app.Action = curryMain(Version)
app.Commands = cli.Commands{
{
Expand Down Expand Up @@ -67,7 +67,7 @@ func main() {
}
}

// curryMain transforms the validator.Main function into an app.Action
// curryMain transforms the kroma-validator.Main function into an app.Action
// This is done to capture the Version of the validator.
func curryMain(version string) func(ctx *cli.Context) error {
return func(ctx *cli.Context) error {
Expand Down
Loading

0 comments on commit 561a3c7

Please sign in to comment.