From 5987a07a6855ece75c5741a27063bd13b9becd32 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Mon, 23 Jan 2023 16:17:58 -0500 Subject: [PATCH 01/18] feat: burn type --- client.go | 1 + main.go | 2 +- mapper.go | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 6a679a3..06ae0fd 100644 --- a/client.go +++ b/client.go @@ -75,6 +75,7 @@ func (c *OpClient) ParseOps( ops = append(ops, feeOps...) ops = append(ops, MintOps(tx, len(ops))...) + ops = append(ops, BurnOps(tx, len(ops))...) traceOps := services.TraceOps(tx.Trace, len(ops)) ops = append(ops, traceOps...) diff --git a/main.go b/main.go index d843824..4666a59 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { ots = append(ots, ot) } ots = append(ots, MintOpType) - // TODO(inphi): add BurnOpType + ots = append(ots, BurnOpType) t.OperationTypes = ots client, err := NewOpClient(cfg) diff --git a/mapper.go b/mapper.go index 9402ace..6098197 100644 --- a/mapper.go +++ b/mapper.go @@ -16,6 +16,7 @@ var ( l1FeeVault = common.HexToAddress("0x420000000000000000000000000000000000001a") MintOpType = "MINT" + BurnOpType = "BURN" ) // FeeOps returns the fee operations for a given transaction @@ -133,3 +134,23 @@ func MintOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Op }, } } + +// FIXME: this is wrong +func BurnOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { + if *tx.Transaction.To() != common.HexToAddress("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead") { + return nil + } + return []*RosettaTypes.Operation{ + { + OperationIdentifier: &RosettaTypes.OperationIdentifier{ + Index: int64(startIndex), + }, + Type: BurnOpType, + Status: RosettaTypes.String(sdkTypes.SuccessStatus), + Account: &RosettaTypes.AccountIdentifier{ + Address: tx.From.String(), + }, + Amount: evmClient.Amount(tx.Transaction.Value(), sdkTypes.Currency), + }, + } +} From c5373ab67894b0aa8e7387664af3a5584290f6a9 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Tue, 24 Jan 2023 16:06:13 -0500 Subject: [PATCH 02/18] fix: split out handlers --- client.go | 9 +++--- handlers/burn.go | 27 +++++++++++++++++ mapper.go => handlers/fees.go | 56 +++-------------------------------- handlers/mint.go | 27 +++++++++++++++++ handlers/ops.go | 39 ++++++++++++++++++++++++ main.go | 5 ++-- 6 files changed, 105 insertions(+), 58 deletions(-) create mode 100644 handlers/burn.go rename mapper.go => handlers/fees.go (62%) create mode 100644 handlers/mint.go create mode 100644 handlers/ops.go diff --git a/client.go b/client.go index 06ae0fd..00e3e17 100644 --- a/client.go +++ b/client.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/coinbase/rosetta-geth-sdk/configuration" + "github.com/mdehoog/op-rosetta/handlers" "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/common" @@ -42,7 +43,7 @@ func (c *OpClient) ParseOps( metadata := map[string]interface{}{} if from != to { - feeOps, err := FeeOps(tx) + feeOps, err := handlers.FeeOps(tx) if err != nil { return nil, err } @@ -68,14 +69,14 @@ func (c *OpClient) ParseOps( return ops, nil } - feeOps, err := FeeOps(tx) + feeOps, err := handlers.FeeOps(tx) if err != nil { return nil, err } ops = append(ops, feeOps...) - ops = append(ops, MintOps(tx, len(ops))...) - ops = append(ops, BurnOps(tx, len(ops))...) + ops = append(ops, handlers.MintOps(tx, len(ops))...) + ops = append(ops, handlers.BurnOps(tx, len(ops))...) traceOps := services.TraceOps(tx.Trace, len(ops)) ops = append(ops, traceOps...) diff --git a/handlers/burn.go b/handlers/burn.go new file mode 100644 index 0000000..4ca8b5a --- /dev/null +++ b/handlers/burn.go @@ -0,0 +1,27 @@ +package handlers + +import ( + evmClient "github.com/coinbase/rosetta-geth-sdk/client" + sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" + RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" +) + +// BurnOps constructs a list of [RosettaTypes.Operation]s for an Optimism Withdrawal or "burn" transaction. +func BurnOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { + if *tx.Transaction.To() != L2ToL1MessagePasser { + return nil + } + return []*RosettaTypes.Operation{ + { + OperationIdentifier: &RosettaTypes.OperationIdentifier{ + Index: int64(startIndex), + }, + Type: BurnOpType, + Status: RosettaTypes.String(sdkTypes.SuccessStatus), + Account: &RosettaTypes.AccountIdentifier{ + Address: tx.From.String(), + }, + Amount: evmClient.Amount(tx.Transaction.Value(), sdkTypes.Currency), + }, + } +} diff --git a/mapper.go b/handlers/fees.go similarity index 62% rename from mapper.go rename to handlers/fees.go index 6098197..cd20dee 100644 --- a/mapper.go +++ b/handlers/fees.go @@ -1,25 +1,16 @@ -package main +package handlers import ( "math/big" evmClient "github.com/coinbase/rosetta-geth-sdk/client" RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" - "github.com/ethereum/go-ethereum/common" EthTypes "github.com/ethereum/go-ethereum/core/types" sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" ) -var ( - baseFeeVault = common.HexToAddress("0x4200000000000000000000000000000000000019") - l1FeeVault = common.HexToAddress("0x420000000000000000000000000000000000001a") - - MintOpType = "MINT" - BurnOpType = "BURN" -) - -// FeeOps returns the fee operations for a given transaction +// FeeOps returns the fee operations for a given transaction. func FeeOps(tx *evmClient.LoadedTransaction) ([]*RosettaTypes.Operation, error) { if tx.Transaction.IsDepositTx() { return nil, nil @@ -89,7 +80,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) ([]*RosettaTypes.Operation, error) Type: sdkTypes.FeeOpType, Status: RosettaTypes.String(sdkTypes.SuccessStatus), Account: &RosettaTypes.AccountIdentifier{ - Address: baseFeeVault.Hex(), + Address: BaseFeeVault.Hex(), }, // Note: The basefee is not actually burned on L2 Amount: evmClient.Amount(tx.FeeBurned, sdkTypes.Currency), @@ -107,7 +98,7 @@ func FeeOps(tx *evmClient.LoadedTransaction) ([]*RosettaTypes.Operation, error) Type: sdkTypes.FeeOpType, Status: RosettaTypes.String(sdkTypes.SuccessStatus), Account: &RosettaTypes.AccountIdentifier{ - Address: l1FeeVault.Hex(), + Address: L1FeeVault.Hex(), }, Amount: evmClient.Amount(receipt.L1Fee, sdkTypes.Currency), }, @@ -115,42 +106,3 @@ func FeeOps(tx *evmClient.LoadedTransaction) ([]*RosettaTypes.Operation, error) return ops, nil } - -func MintOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { - if tx.Transaction.Mint() == nil { - return nil - } - return []*RosettaTypes.Operation{ - { - OperationIdentifier: &RosettaTypes.OperationIdentifier{ - Index: int64(startIndex), - }, - Type: MintOpType, - Status: RosettaTypes.String(sdkTypes.SuccessStatus), - Account: &RosettaTypes.AccountIdentifier{ - Address: tx.From.String(), - }, - Amount: evmClient.Amount(tx.Transaction.Mint(), sdkTypes.Currency), - }, - } -} - -// FIXME: this is wrong -func BurnOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { - if *tx.Transaction.To() != common.HexToAddress("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead") { - return nil - } - return []*RosettaTypes.Operation{ - { - OperationIdentifier: &RosettaTypes.OperationIdentifier{ - Index: int64(startIndex), - }, - Type: BurnOpType, - Status: RosettaTypes.String(sdkTypes.SuccessStatus), - Account: &RosettaTypes.AccountIdentifier{ - Address: tx.From.String(), - }, - Amount: evmClient.Amount(tx.Transaction.Value(), sdkTypes.Currency), - }, - } -} diff --git a/handlers/mint.go b/handlers/mint.go new file mode 100644 index 0000000..3bfbe9e --- /dev/null +++ b/handlers/mint.go @@ -0,0 +1,27 @@ +package handlers + +import ( + evmClient "github.com/coinbase/rosetta-geth-sdk/client" + sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" + RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" +) + +// MintOps constructs a list of [RosettaTypes.Operation]s for an Optimism Deposit or "mint" transaction. +func MintOps(tx *evmClient.LoadedTransaction, startIndex int) []*RosettaTypes.Operation { + if tx.Transaction.Mint() == nil { + return nil + } + return []*RosettaTypes.Operation{ + { + OperationIdentifier: &RosettaTypes.OperationIdentifier{ + Index: int64(startIndex), + }, + Type: MintOpType, + Status: RosettaTypes.String(sdkTypes.SuccessStatus), + Account: &RosettaTypes.AccountIdentifier{ + Address: tx.From.String(), + }, + Amount: evmClient.Amount(tx.Transaction.Mint(), sdkTypes.Currency), + }, + } +} diff --git a/handlers/ops.go b/handlers/ops.go new file mode 100644 index 0000000..57fff33 --- /dev/null +++ b/handlers/ops.go @@ -0,0 +1,39 @@ +// Package handlers handles translating transactions into [RosettaTypes.Operation]s. +package handlers + +import ( + "github.com/ethereum/go-ethereum/common" +) + +const ( + // MintOpType is a [RosettaTypes.Operation] type for an Optimism Deposit or "mint" transaction. + MintOpType = "MINT" + // BurnOpType is a [RosettaTypes.Operation] type for an Optimism Withdrawal or "burn" transaction. + BurnOpType = "BURN" +) + +// Optimism Predeploy Addresses +// See [PredeployedContracts] for more information. +// +// [PredeployedContracts]: https://github.com/ethereum-optimism/optimism/blob/d8e328ae936c6a5f3987c04cbde7bd94403a96a0/specs/predeploys.md +var ( + // The BaseFeeVault predeploy receives the basefees on L2. + // The basefee is not burnt on L2 like it is on L1. + // Once the contract has received a certain amount of fees, + // the ETH can be permissionlessly withdrawn to an immutable address on L1. + BaseFeeVault = common.HexToAddress("0x4200000000000000000000000000000000000019") + + // The L1FeeVault predeploy receives the L1 portion of the transaction fees. + // Once the contract has received a certain amount of fees, + // the ETH can be permissionlessly withdrawn to an immutable address on L1. + L1FeeVault = common.HexToAddress("0x420000000000000000000000000000000000001a") + + // The L2ToL1MessagePasser stores commitments to withdrawal transactions. + // When a user is submitting the withdrawing transaction on L1, + // they provide a proof that the transaction that they withdrew on L2 is in + // the sentMessages mapping of this contract. + // + // Any withdrawn ETH accumulates into this contract on L2 and can be + // permissionlessly removed from the L2 supply by calling the burn() function. + L2ToL1MessagePasser = common.HexToAddress("0x4200000000000000000000000000000000000016") +) diff --git a/main.go b/main.go index 4666a59..ba584fb 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "github.com/coinbase/rosetta-geth-sdk/types" "github.com/coinbase/rosetta-geth-sdk/utils" + "github.com/mdehoog/op-rosetta/handlers" ) func main() { @@ -22,8 +23,8 @@ func main() { } ots = append(ots, ot) } - ots = append(ots, MintOpType) - ots = append(ots, BurnOpType) + ots = append(ots, handlers.MintOpType) + ots = append(ots, handlers.BurnOpType) t.OperationTypes = ots client, err := NewOpClient(cfg) From 53d473e8ab0ed6bc5f6b28a968d5f784b79c7877 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Tue, 24 Jan 2023 17:04:48 -0500 Subject: [PATCH 03/18] fix: overhaul --- Makefile | 19 +++++++++++++-- README.md | 28 ++++++++++++++++++++-- app/app.go | 49 ++++++++++++++++++++++++++++++++++++++ client.go => app/client.go | 7 +++--- config.go => app/config.go | 5 ++-- cmd/main.go | 35 +++++++++++++++++++++++++++ go.mod | 6 +++++ go.sum | 5 ++++ main.go | 39 ------------------------------ utils/log.go | 17 +++++++++++++ 10 files changed, 160 insertions(+), 50 deletions(-) create mode 100644 app/app.go rename client.go => app/client.go (97%) rename config.go => app/config.go (98%) create mode 100644 cmd/main.go delete mode 100644 main.go create mode 100644 utils/log.go diff --git a/Makefile b/Makefile index e9d1113..95c0865 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,18 @@ -.PHONY: build +all: clean build test lint + +clean: + rm -rf bin/op-rosetta + build: - go build -o bin/op-rosetta . + env GO111MODULE=on go build -o bin/op-rosetta ./cmd + +test: + go test -v ./... + +lint: + golangci-lint run -E asciicheck,goimports,misspell ./... + +.PHONY: \ + test \ + lint \ + build diff --git a/README.md b/README.md index a4df88a..bdd42c3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,18 @@ -# op-rosetta +
+
+
+ Rosetta +
+

op-rosetta is a Rosetta-compatible API for Optimism Bedrock, a low-cost and lightning-fast Ethereum L2 blockchain. It is built on coinbase/rosetta-geth-sdk.

+
+
+ +## Overview + +`op-rosetta` provides an executable [client](./app/client.go) that plugs into the [rosetta-geth-sdk](https://github.com/coinbase/rosetta-geth-sdk). This provides Rosetta API compatibility for Optimism Bedrock, a low-cost and lightning-fast Ethereum L2 blockchain. + +To learn more about the Rosetta API, you can find more online at [rosetta-api.org](https://www.rosetta-api.org/). -`op-rosetta` is a Rosetta-compatible API for Optimism Bedrock. It is based on [coinbase/rosetta-geth-sdk](https://github.com/coinbase/rosetta-geth-sdk). ### Running @@ -9,3 +21,15 @@ make build export CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' MODE=ONLINE PORT=5000 NETWORK=mainnet GETH=https://mainnet.optimism.io bin/op-rosetta ``` + +### Testing with `rosetta-cli` + +To validate `rosetta-ethereum`, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install) +and run one of the following commands: +* `rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `testnet` node. It also ensures that the implementation does not miss any balance-changing operations. +* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the `testnet` network. +* `rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `mainnet` node. It also ensures that the implementation does not miss any balance-changing operations. + +### License + +All files within this repository, including code adapted from [rosetta-geth-sdk](https://github.com/coinbase/rosetta-geth-sdk), is licensed under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0) unless explicitly stated otherwise. diff --git a/app/app.go b/app/app.go new file mode 100644 index 0000000..12ffb1b --- /dev/null +++ b/app/app.go @@ -0,0 +1,49 @@ +// Package app contains the primary functionality of op-rosetta. +package app + +import ( + "log" + + "github.com/coinbase/rosetta-geth-sdk/types" + "github.com/coinbase/rosetta-geth-sdk/utils" + "github.com/mdehoog/op-rosetta/handlers" + "github.com/urfave/cli" +) + +// Main is the entrypoint into op-rosetta. This method returns a +// closure that executes the service and blocks until the service exits. The use +// of a closure allows the parameters bound to the top-level main package, e.g. +// GitVersion, to be captured and used once the function is executed. +func Main(version string) func(cliCtx *cli.Context) error { + return func(cliCtx *cli.Context) error { + cfg, err := LoadConfiguration() + if err != nil { + log.Fatalf("unable to load configuration: %v", err) + } + + t := types.LoadTypes() + var ots []string + for _, ot := range t.OperationTypes { + if ot == types.MinerRewardOpType || ot == types.UncleRewardOpType { + // Optimism does not have miner or uncle reward type ops + continue + } + ots = append(ots, ot) + } + ots = append(ots, handlers.MintOpType) + ots = append(ots, handlers.BurnOpType) + t.OperationTypes = ots + + client, err := NewOpClient(cfg) + if err != nil { + log.Fatalf("cannot initialize client: %v", err) + } + + err = utils.BootStrap(cfg, t, types.Errors, client) + if err != nil { + log.Fatalf("unable to bootstrap Rosetta server: %v", err) + } + + return nil + } +} diff --git a/client.go b/app/client.go similarity index 97% rename from client.go rename to app/client.go index 00e3e17..8c65400 100644 --- a/client.go +++ b/app/client.go @@ -1,4 +1,4 @@ -package main +package app import ( "context" @@ -16,7 +16,6 @@ import ( evmClient "github.com/coinbase/rosetta-geth-sdk/client" "github.com/coinbase/rosetta-geth-sdk/services" sdkTypes "github.com/coinbase/rosetta-geth-sdk/types" - "github.com/coinbase/rosetta-sdk-go/types" RosettaTypes "github.com/coinbase/rosetta-sdk-go/types" EthTypes "github.com/ethereum/go-ethereum/core/types" ) @@ -31,8 +30,8 @@ const ( func (c *OpClient) ParseOps( tx *evmClient.LoadedTransaction, -) ([]*types.Operation, error) { - var ops []*types.Operation +) ([]*RosettaTypes.Operation, error) { + var ops []*RosettaTypes.Operation if tx.Receipt.Type == L1ToL2DepositType && len(tx.Trace) > 0 && tx.Transaction.IsSystemTx() { trace := tx.Trace[0] diff --git a/config.go b/app/config.go similarity index 98% rename from config.go rename to app/config.go index d7f1ce1..4853f6f 100644 --- a/config.go +++ b/app/config.go @@ -1,4 +1,4 @@ -package main +package app import ( "encoding/json" @@ -7,7 +7,6 @@ import ( "os" "strconv" - "github.com/coinbase/rosetta-sdk-go/types" "github.com/ethereum/go-ethereum/params" "github.com/coinbase/rosetta-geth-sdk/configuration" @@ -134,7 +133,7 @@ func LoadConfiguration() (*configuration.Configuration, error) { return nil, fmt.Errorf("unable to parse chain config: %w", err) } - config.Network = &types.NetworkIdentifier{ + config.Network = &RosettaTypes.NetworkIdentifier{ Blockchain: blockchain, Network: networkValue, } diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..dfbdcf5 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "fmt" + "os" + + "github.com/mdehoog/op-rosetta/app" + "github.com/mdehoog/op-rosetta/utils" + "github.com/urfave/cli" + + "github.com/ethereum/go-ethereum/log" +) + +var ( + Version = "v0.1.0" + GitCommit = "" + GitDate = "" +) + +func main() { + utils.SetupDefaults() + + cliApp := cli.NewApp() + cliApp.Flags = []cli.Flag{} + cliApp.Version = fmt.Sprintf("%s-%s-%s", Version, GitCommit, GitDate) + cliApp.Name = "op-rosetta" + cliApp.Usage = "Optimism Rosetta Service" + cliApp.Description = "Service for translating Optimism transactions into Rosetta Operations" + + cliApp.Action = app.Main(Version) + err := cliApp.Run(os.Args) + if err != nil { + log.Crit("op-rosetta failed", "message", err) + } +} diff --git a/go.mod b/go.mod index a53b523..55e763e 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,11 @@ require ( github.com/ethereum/go-ethereum v1.10.26 ) +require ( + github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect +) + require ( github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect github.com/VictoriaMetrics/fastcache v1.6.0 // indirect @@ -48,6 +53,7 @@ require ( github.com/tklauser/go-sysconf v0.3.5 // indirect github.com/tklauser/numcpus v0.2.2 // indirect github.com/tyler-smith/go-bip39 v1.0.2 // indirect + github.com/urfave/cli v1.22.12 golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect diff --git a/go.sum b/go.sum index a65e3a9..28f22a6 100644 --- a/go.sum +++ b/go.sum @@ -26,6 +26,7 @@ github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.3/go.mod h1:KLF4gFr6DcKFZwSu github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.3.0/go.mod h1:tPaiy8S5bQ+S5sOiDlINkp7+Ef339+Nz5L5XO+cnOHo= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw= @@ -438,6 +439,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= @@ -449,6 +451,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= @@ -466,6 +469,8 @@ github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef/go.mod h1:s github.com/tyler-smith/go-bip39 v1.0.2 h1:+t3w+KwLXO6154GNJY+qUtIxLTmFjfUmpguQT1OlOT8= github.com/tyler-smith/go-bip39 v1.0.2/go.mod h1:sJ5fKU0s6JVwZjjcUEX2zFOnvq0ASQ2K9Zr6cf67kNs= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= +github.com/urfave/cli v1.22.12 h1:igJgVw1JdKH+trcLWLeLwZjU9fEfPesQ+9/e4MQ44S8= +github.com/urfave/cli v1.22.12/go.mod h1:sSBEIC79qR6OvcmsD4U3KABeOTxDqQtdDnaFuUN30b8= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa h1:5SqCsI/2Qya2bCzK15ozrqo2sZxkh0FHynJZOTVoV6Q= github.com/urfave/cli/v2 v2.17.2-0.20221006022127-8f469abc00aa/go.mod h1:1CNUng3PtjQMtRzJO4FMXBQvkGtuYRxxiR9xMa7jMwI= diff --git a/main.go b/main.go deleted file mode 100644 index ba584fb..0000000 --- a/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "log" - - "github.com/coinbase/rosetta-geth-sdk/types" - "github.com/coinbase/rosetta-geth-sdk/utils" - "github.com/mdehoog/op-rosetta/handlers" -) - -func main() { - cfg, err := LoadConfiguration() - if err != nil { - log.Fatalf("unable to load configuration: %v", err) - } - - t := types.LoadTypes() - var ots []string - for _, ot := range t.OperationTypes { - if ot == types.MinerRewardOpType || ot == types.UncleRewardOpType { - // Optimism does not have miner or uncle reward type ops - continue - } - ots = append(ots, ot) - } - ots = append(ots, handlers.MintOpType) - ots = append(ots, handlers.BurnOpType) - t.OperationTypes = ots - - client, err := NewOpClient(cfg) - if err != nil { - log.Fatalf("cannot initialize client: %v", err) - } - - err = utils.BootStrap(cfg, t, types.Errors, client) - if err != nil { - log.Fatalf("unable to bootstrap Rosetta server: %v", err) - } -} diff --git a/utils/log.go b/utils/log.go new file mode 100644 index 0000000..b4694e9 --- /dev/null +++ b/utils/log.go @@ -0,0 +1,17 @@ +package utils + +import ( + "os" + + "github.com/ethereum/go-ethereum/log" +) + +// SetupDefaults sets up the default logging level. +func SetupDefaults() { + log.Root().SetHandler( + log.LvlFilterHandler( + log.LvlInfo, + log.StreamHandler(os.Stdout, log.TerminalFormat(true)), + ), + ) +} From 71d1aeb7023e7f600d0156f17e3f16695ca465c7 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 12:18:00 -0500 Subject: [PATCH 04/18] overhaul --- .env.example | 13 ++ .gitignore | 4 + Dockerfile | 136 ++++++++++++ Makefile | 35 +++ README.md | 12 +- configs/README.md | 73 +++++++ configs/mainnet/bootstrap_balances.json | 82 +++++++ configs/mainnet/config.json | 26 +++ configs/mainnet/exempt_accounts.json | 11 + configs/optimism/goerli.json | 34 +++ configs/optimism/mainnet.json | 34 +++ configs/testnet/bootstrap_balances.json | 82 +++++++ configs/testnet/config.json | 35 +++ configs/testnet/config_erc20.json | 34 +++ configs/testnet/exempt_accounts.json | 11 + configs/testnet/optimism.ros | 112 ++++++++++ configs/testnet/optimism_erc20.ros | 114 ++++++++++ entrypoint.sh | 24 +++ geth.toml | 17 ++ tokenList.json | 16 ++ utils/call_tracer.js | 271 ++++++++++++++++++++++++ 21 files changed, 1170 insertions(+), 6 deletions(-) create mode 100644 .env.example create mode 100644 Dockerfile create mode 100644 configs/README.md create mode 100644 configs/mainnet/bootstrap_balances.json create mode 100644 configs/mainnet/config.json create mode 100644 configs/mainnet/exempt_accounts.json create mode 100644 configs/optimism/goerli.json create mode 100644 configs/optimism/mainnet.json create mode 100644 configs/testnet/bootstrap_balances.json create mode 100644 configs/testnet/config.json create mode 100644 configs/testnet/config_erc20.json create mode 100644 configs/testnet/exempt_accounts.json create mode 100644 configs/testnet/optimism.ros create mode 100644 configs/testnet/optimism_erc20.ros create mode 100644 entrypoint.sh create mode 100644 geth.toml create mode 100644 tokenList.json create mode 100644 utils/call_tracer.js diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..95ea49d --- /dev/null +++ b/.env.example @@ -0,0 +1,13 @@ +#################################################### +# Environment Variables +# - Make a copy of this file and rename it to .env +# - Then fill in the values for your environment +# - These will be sourced from the Makefile +#################################################### + +# Optimism Goerli Node URL +OPTIMISM_GOERLI_NODE= + +# Optimism Mainnet Node URL +OPTIMISM_MAINNET_NODE= + diff --git a/.gitignore b/.gitignore index bee07ca..090f03a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ /bin/ /cli-data/* rosetta-cli-conf/* + + +# Environment Variables +.env \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..605eb05 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,136 @@ +############################################################## +## Build golang +############################################################## +FROM ubuntu:20.04 as golang + +RUN mkdir -p /app && chown -R nobody:nogroup /app +WORKDIR /app + +RUN apt-get update && apt-get install -y curl make gcc g++ git +ENV GOLANG_VERSION 1.16.8 +ENV GOLANG_DOWNLOAD_SHA256 f32501aeb8b7b723bc7215f6c373abb6981bbc7e1c7b44e9f07317e1a300dce2 +ENV GOLANG_DOWNLOAD_URL https://golang.org/dl/go$GOLANG_VERSION.linux-amd64.tar.gz + +RUN curl -fsSL "$GOLANG_DOWNLOAD_URL" -o golang.tar.gz \ + && echo "$GOLANG_DOWNLOAD_SHA256 golang.tar.gz" | sha256sum -c - \ + && tar -C /usr/local -xzf golang.tar.gz \ + && rm golang.tar.gz + +ENV GOPATH /go +ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH +RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" + +############################################################## +## Build geth +############################################################## + +# TODO: + +############################################################## +## Build op-rosetta +############################################################## +FROM golang as rosetta + +COPY . app +RUN cd app && go build + +# TODO: Only copy necessary files split into various packages +# # Copy necessary files +# RUN mv src/* /app/op-rosetta \ +# && mkdir /app/optimism \ +# && mv utils/call_tracer.js /app/optimism/call_tracer.js \ +# && mv geth.toml /app/optimism/geth.toml \ +# && mv tokenList.json /app/tokenList.json \ +# && rm -rf src + +## Build Final Image +FROM ubuntu:20.04 +RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates + +# Construct owned directories +RUN mkdir -p /app \ + && chown -R nobody:nogroup /app \ + && mkdir -p /data \ + && chown -R nobody:nogroup /data + +# Set the working directory +WORKDIR /app + +# Copy app files from rosetta +COPY --from=rosetta /app/* /app/* + +# TODO: Only copy necessary files +# COPY --from=rosetta /app/rosetta-ethereum /app/rosetta-ethereum +# COPY --from=rosetta /app/tokenList.json /app/tokenList.json + +# Set permissions for everything added to /app +RUN chmod -R 755 /app/* + +# Run the op-rosetta binary +CMD ["/app/op-rosetta", "run"] + + + + + + + + + + + + + + +# Compile geth +FROM golang-builder as geth-builder + +# VERSION: go-ethereum v.1.10.16 +RUN git clone https://github.com/ethereum/go-ethereum \ + && cd go-ethereum \ + && git checkout 20356e57b119b4e70ce47665a71964434e15200d + +RUN cd go-ethereum \ + && make geth + +RUN mv go-ethereum/build/bin/geth /app/geth \ + && rm -rf go-ethereum + +# Compile rosetta-ethereum +FROM golang-builder as rosetta-builder + +# Copy binary from geth-builder +COPY --from=geth-builder /app/geth /app/geth + +# Use native remote build context to build in any directory +COPY . src + +RUN mv src/geth.toml /app/geth.toml \ + && mv src/entrypoint.sh /app/entrypoint.sh \ + && rm -rf src + +## Build Final Image +FROM ubuntu:20.04 + +RUN apt-get update && apt-get install -y ca-certificates && update-ca-certificates + +RUN mkdir -p /app \ + && chown -R nobody:nogroup /app \ + && mkdir -p /data \ + && chown -R nobody:nogroup /data + +WORKDIR /app + +# Copy binary from geth-builder +COPY --from=geth-builder /app/geth /app/geth + +# Copy binary from rosetta-builder +COPY --from=rosetta-builder /app /app + +# Set permissions for everything added to /app +RUN chmod -R 755 /app/* + +EXPOSE 8545 8546 30303 30303/udp + +ENTRYPOINT ["/app/entrypoint.sh"] + diff --git a/Makefile b/Makefile index 95c0865..33ead0d 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,10 @@ +# Load in the .env file +include .env + +# General Config +PWD=$(shell pwd) +NOFILE=100000 + all: clean build test lint clean: @@ -16,3 +23,31 @@ lint: test \ lint \ build + +# Runs an instance of `op-rosetta` configured for Optimism Mainnet +run-optimism-mainnet: + make build \ + CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \ + MODE=ONLINE \ + PORT=8080 \ + BLOCKCHAIN=Optimism \ + NETWORK=Mainnet \ + ENABLE_TRACE_CACHE=true \ + ENABLE_GETH_TRACER=true \ + GETH=${OPTIMISM_MAINNET_NODE} \ + GENESIS_BLOCK_HASH=0xa89b19033c8b43365e244f425a7e4acb5bae21d1893e1be0eb8cddeb29950d72 \ + bin/op-rosetta + +# Runs an instance of `op-rosetta` configured for Optimism Goerli +run-optimism-goerli: + CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \ + MODE=ONLINE \ + PORT=8080 \ + BLOCKCHAIN=Optimism \ + NETWORK=Goerli \ + GETH=${OPTIMISM_GOERLI_NODE} \ + ENABLE_TRACE_CACHE=true \ + ENABLE_GETH_TRACER=true \ + GENESIS_BLOCK_HASH=0x0f783549ea4313b784eadd9b8e8a69913b368b7366363ea814d7707ac505175f \ + bin/op-rosetta + diff --git a/README.md b/README.md index bdd42c3..6a65422 100644 --- a/README.md +++ b/README.md @@ -16,19 +16,19 @@ To learn more about the Rosetta API, you can find more online at [rosetta-api.or ### Running +To run the `op-rosetta` client, you can use the following command: + ``` make build export CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' -MODE=ONLINE PORT=5000 NETWORK=mainnet GETH=https://mainnet.optimism.io bin/op-rosetta +MODE=ONLINE PORT=8080 NETWORK=mainnet GETH=https://mainnet.optimism.io bin/op-rosetta ``` ### Testing with `rosetta-cli` -To validate `rosetta-ethereum`, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install) -and run one of the following commands: -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `testnet` node. It also ensures that the implementation does not miss any balance-changing operations. -* `rosetta-cli check:construction --configuration-file rosetta-cli-conf/testnet/config.json` - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the `testnet` network. -* `rosetta-cli check:data --configuration-file rosetta-cli-conf/mainnet/config.json` - This command validates that the Data API implementation is correct using the ethereum `mainnet` node. It also ensures that the implementation does not miss any balance-changing operations. +_NOTE: `op-rosetta` must be running on the specified host and port provided in the configuration file. For local testing, this can be done as described in the [Running](#running) section, which will run an instance on localhost, port 8080._ + +See [configs/README.md](./configs/README.md) for more information. ### License diff --git a/configs/README.md b/configs/README.md new file mode 100644 index 0000000..dffa90b --- /dev/null +++ b/configs/README.md @@ -0,0 +1,73 @@ +## configs + +A collection of configuration files used to test the `op-rosetta` client using [`rosetta-cli`](https://github.com/coinbase/rosetta-cli). + +These config files were built using the [rosett-cli documentation](https://www.rosetta-api.org/docs/rosetta_test.html). + + +### Setup + +First, [install `rosetta-cli`](https://github.com/coinbase/rosetta-cli#install). + +If the installation script doesn't work (on mac it may not), try cloning the repo and installing from source: + +```bash +gh repo clone coinbase/rosetta-cli +cd rosetta-cli +make install +``` + + +### Testing + +_NOTE: `op-rosetta` must be running on the specified host and port provided in the configuration file. For local testing, this can be done as described in the root [README.md](../README.md#running) section, which will run an instance on localhost, port 8080._ + +To validate with `rosetta-cli`, run one of the following commands: + +* `rosetta-cli check:data --configuration-file optimism/config.json` - This command validates that the Data API implementation is correct using the ethereum `optimism` node. It also ensures that the implementation does not miss any balance-changing operations. + +* `rosetta-cli check:construction --configuration-file optimism/config.json` - This command validates the Construction API implementation. It also verifies transaction construction, signing, and submissions to the `optimism` network. + +* `rosetta-cli check:data --configuration-file optimism/config.json` - This command validates that the Data API implementation is correct using the ethereum `optimism` node. It also ensures that the implementation does not miss any balance-changing operations. + + +### Reference + +The `rosetta-cli` offers a number of commands useful for checking the implementation of the `op-rosetta` client. For more information, run `rosetta-cli --help` for the following output: + +``` +CLI for the Rosetta API + +Usage: + rosetta-cli [command] + +Available Commands: + check:construction Check the correctness of a Rosetta Construction API Implementation + check:data Check the correctness of a Rosetta Data API Implementation + check:perf Benchmark performance of time-critical endpoints of Asset Issuer's Rosetta Implementation + check:spec Check that a Rosetta implementation satisfies Rosetta spec + completion Generate the autocompletion script for the specified shell + configuration:create Create a default configuration file at the provided path + configuration:validate Ensure a configuration file at the provided path is formatted correctly + help Help about any command + utils:asserter-configuration Generate a static configuration file for the Asserter + utils:train-zstd Generate a zstd dictionary for enhanced compression performance + version Print rosetta-cli version + view:balance View an account balance + view:block View a block + view:networks View all network statuses + +Flags: + --block-profile string Save the pprof block profile in the specified file + --configuration-file string Configuration file that provides connection and test settings. + If you would like to generate a starter configuration file (populated + with the defaults), run rosetta-cli configuration:create. + + Any fields not populated in the configuration file will be populated with + default values. + --cpu-profile string Save the pprof cpu profile in the specified file + -h, --help help for rosetta-cli + --mem-profile string Save the pprof mem profile in the specified file + +Use "rosetta-cli [command] --help" for more information about a command. +``` \ No newline at end of file diff --git a/configs/mainnet/bootstrap_balances.json b/configs/mainnet/bootstrap_balances.json new file mode 100644 index 0000000..4383ad6 --- /dev/null +++ b/configs/mainnet/bootstrap_balances.json @@ -0,0 +1,82 @@ +[ + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000001" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000002" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000003" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000004" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000005" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000006" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000007" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000008" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + } +] \ No newline at end of file diff --git a/configs/mainnet/config.json b/configs/mainnet/config.json new file mode 100644 index 0000000..0b099e5 --- /dev/null +++ b/configs/mainnet/config.json @@ -0,0 +1,26 @@ +{ + "network": { + "blockchain": "Ethereum", + "network": "Mainnet" + }, + "data_directory": "cli-data", + "http_timeout": 300, + "max_retries": 15, + "max_online_connections": 500, + "max_sync_concurrency": 64, + "tip_delay": 120, + "compression_disabled":true, + "memory_limit_disabled":true, + "data": { + "initial_balance_fetch_disabled":true, + "active_reconciliation_concurrency": 32, + "bootstrap_balances": "bootstrap_balances.json", + "exempt_accounts": "exempt_accounts.json", + "end_conditions": { + "reconciliation_coverage": { + "coverage": 0.95, + "from_tip": true + } + } + } +} diff --git a/configs/mainnet/exempt_accounts.json b/configs/mainnet/exempt_accounts.json new file mode 100644 index 0000000..940dbd1 --- /dev/null +++ b/configs/mainnet/exempt_accounts.json @@ -0,0 +1,11 @@ +[ + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000000" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + } + } +] diff --git a/configs/optimism/goerli.json b/configs/optimism/goerli.json new file mode 100644 index 0000000..5365b71 --- /dev/null +++ b/configs/optimism/goerli.json @@ -0,0 +1,34 @@ +{ + "network": { + "blockchain": "Optimism", + "network": "Goerli", + "sub_network_identifier": null + }, + "online_url": "http://localhost:8080", + "data_directory": "", + "http_timeout": 300, + "max_retries": 15, + "max_online_connections": 500, + "force_retry": true, + "max_sync_concurrency": 64, + "tip_delay": 120, + "max_reorg_depth": 64, + "log_configuration": false, + "compression_disabled": true, + "l0_in_memory_enabled": true, + "all_in_memory_enabled": true, + "table_size": 1, + "value_log_file_size": 1024, + "construction": null, + "data": { + "reconciliation_disabled": true, + "inactive_discrepancy_search_disabled": true, + "balance_tracking_disabled": true, + "initial_balance_fetch_disabled":true, + "active_reconciliation_concurrency": 32, + "bootstrap_balances": "", + "end_conditions": { + "tip": true + } + } +} diff --git a/configs/optimism/mainnet.json b/configs/optimism/mainnet.json new file mode 100644 index 0000000..f1d4aae --- /dev/null +++ b/configs/optimism/mainnet.json @@ -0,0 +1,34 @@ +{ + "network": { + "blockchain": "Optimism", + "network": "Mainnet", + "sub_network_identifier": null + }, + "online_url": "http://localhost:8080", + "data_directory": "", + "http_timeout": 300, + "max_retries": 15, + "max_online_connections": 500, + "force_retry": true, + "max_sync_concurrency": 64, + "tip_delay": 120, + "max_reorg_depth": 64, + "log_configuration": false, + "compression_disabled": true, + "l0_in_memory_enabled": true, + "all_in_memory_enabled": true, + "table_size": 1, + "value_log_file_size": 1024, + "construction": null, + "data": { + "reconciliation_disabled": true, + "inactive_discrepancy_search_disabled": true, + "balance_tracking_disabled": true, + "initial_balance_fetch_disabled":true, + "active_reconciliation_concurrency": 32, + "bootstrap_balances": "", + "end_conditions": { + "tip": true + } + } +} diff --git a/configs/testnet/bootstrap_balances.json b/configs/testnet/bootstrap_balances.json new file mode 100644 index 0000000..4383ad6 --- /dev/null +++ b/configs/testnet/bootstrap_balances.json @@ -0,0 +1,82 @@ +[ + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000001" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000002" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000003" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000004" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000005" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000006" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000007" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + }, + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000008" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + }, + "value": "1" + } +] \ No newline at end of file diff --git a/configs/testnet/config.json b/configs/testnet/config.json new file mode 100644 index 0000000..9471061 --- /dev/null +++ b/configs/testnet/config.json @@ -0,0 +1,35 @@ +{ + "network": { + "blockchain": "Optimism", + "network": "Mainnet" + }, + "data_directory": "cli-data", + "http_timeout": 300, + "max_retries": 15, + "max_online_connections": 500, + "max_sync_concurrency": 64, + "tip_delay": 120, + "compression_disabled":true, + "memory_limit_disabled":true, + "construction": { + "stale_depth": 3, + "broadcast_limit": 5, + "constructor_dsl_file": "optimism.ros", + "end_conditions": { + "create_account": 10, + "transfer": 20 + } + }, + "data": { + "initial_balance_fetch_disabled":true, + "active_reconciliation_concurrency": 32, + "bootstrap_balances": "bootstrap_balances.json", + "exempt_accounts": "exempt_accounts.json", + "end_conditions": { + "reconciliation_coverage": { + "coverage": 0.95, + "from_tip": true + } + } + } +} diff --git a/configs/testnet/config_erc20.json b/configs/testnet/config_erc20.json new file mode 100644 index 0000000..eb7fb2f --- /dev/null +++ b/configs/testnet/config_erc20.json @@ -0,0 +1,34 @@ +{ + "network": { + "blockchain": "Ethereum", + "network": "Ropsten" + }, + "data_directory": "cli-data", + "http_timeout": 300, + "max_retries": 15, + "max_online_connections": 500, + "max_sync_concurrency": 64, + "tip_delay": 120, + "compression_disabled":true, + "memory_limit_disabled":true, + "construction": { + "stale_depth": 5, + "broadcast_limit": 5, + "constructor_dsl_file": "optimism_erc20.ros", + "end_conditions": { + "create_account": 10, + "simple_transfer_erc20": 10 + } + }, + "data": { + "initial_balance_fetch_disabled":true, + "active_reconciliation_concurrency": 32, + "bootstrap_balances": "bootstrap_balances.json", + "end_conditions": { + "reconciliation_coverage": { + "coverage": 0.95, + "from_tip": true + } + } + } +} diff --git a/configs/testnet/exempt_accounts.json b/configs/testnet/exempt_accounts.json new file mode 100644 index 0000000..940dbd1 --- /dev/null +++ b/configs/testnet/exempt_accounts.json @@ -0,0 +1,11 @@ +[ + { + "account_identifier": { + "address": "0x0000000000000000000000000000000000000000" + }, + "currency": { + "symbol": "ETH", + "decimals": 18 + } + } +] diff --git a/configs/testnet/optimism.ros b/configs/testnet/optimism.ros new file mode 100644 index 0000000..7a3f845 --- /dev/null +++ b/configs/testnet/optimism.ros @@ -0,0 +1,112 @@ +create_account(1){ + create{ + network = {"network":"Testnet", "blockchain":"Optimism"}; + key = generate_key({"curve_type": "secp256k1"}); + account = derive({ + "network_identifier": {{network}}, + "public_key": {{key.public_key}} + }); + + // If the account is not saved, the key will be lost! + save_account({ + "account_identifier": {{account.account_identifier}}, + "keypair": {{key}} + }); + } +} + +transfer(10){ + transfer{ + transfer.network = {"network":"Testnet", "blockchain":"Optimism"}; + currency = {"symbol":"ETH", "decimals":18}; + sender = find_balance({ + "minimum_balance":{ + "value": "10000000000000000", + "currency": {{currency}} + } + }); + + // Set the recipient_amount as some value <= sender.balance-max_fee + max_fee = "84000000000000"; + available_amount = {{sender.balance.value}} - {{max_fee}}; + recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}}); + print_message({"recipient_amount":{{recipient_amount}}}); + + // Find recipient and construct operations + sender_amount = 0 - {{recipient_amount}}; + recipient = find_balance({ + "not_account_identifier":[{{sender.account_identifier}}], + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit": 100, + "create_probability": 50 + }); + transfer.confirmation_depth = "1"; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"CALL", + "account":{{sender.account_identifier}}, + "amount":{ + "value":{{sender_amount}}, + "currency":{{currency}} + } + }, + { + "operation_identifier":{"index":1}, + "type":"CALL", + "account":{{recipient.account_identifier}}, + "amount":{ + "value":{{recipient_amount}}, + "currency":{{currency}} + } + } + ]; + } +} + +return_funds(10){ + // TODO: add suggested fee dry run to ensure account fully cleared + transfer{ + transfer.network = {"network":"Testnet", "blockchain":"Optimism"}; + currency = {"symbol":"ETH", "decimals":18}; + max_fee = "84000000000000"; + sender = find_balance({ + "minimum_balance":{ + "value": {{max_fee}}, + "currency": {{currency}} + } + }); + + // Set the recipient_amount as some sender.balance-max_fee + available_amount = {{sender.balance.value}} - {{max_fee}}; + print_message({"available_amount":{{available_amount}}}); + sender_amount = 0 - {{available_amount}}; + + // Provide a static address as the recipient and construct operations + faucet = {"address":"0x9670d6977d0b10130E5d4916c9134363281B6B0e"}; + transfer.confirmation_depth = "1"; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"CALL", + "account":{{sender.account_identifier}}, + "amount":{ + "value":{{sender_amount}}, + "currency":{{currency}} + } + }, + { + "operation_identifier":{"index":1}, + "type":"CALL", + "account":{{faucet}}, + "amount":{ + "value":{{available_amount}}, + "currency":{{currency}} + } + } + ]; + } +} diff --git a/configs/testnet/optimism_erc20.ros b/configs/testnet/optimism_erc20.ros new file mode 100644 index 0000000..284f57a --- /dev/null +++ b/configs/testnet/optimism_erc20.ros @@ -0,0 +1,114 @@ +request_funds(1){ + find_account{ + currency = {"symbol":"ETH", "decimals":18}; + // TODO(inphi): Change the symbol to "OP" once final contract version is deployed + erc20_currency = {"symbol":"symbol", "decimals":18, "metadata": {"token_address": "0x9A4240883d1b4b82f8E9F21bEdD1b95Fb5176e4d"}}; + random_account = find_balance({ + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit":1 + }); + }, + + // Create a separate scenario to request funds so that + // the address we are using to request funds does not + // get rolled back if funds do not yet exist. + request{ + loaded_account = find_balance({ + "account_identifier": {{random_account.account_identifier}}, + "minimum_balance":{ + "value": "10000000000000000", // 0.01 ETH + "currency": {{currency}} + } + }); + + loaded_account2 = find_balance({ + "account_identifier": {{random_account.account_identifier}}, + "minimum_balance":{ + "value": "10000000000000000", // 0.01 OP + "currency": {{erc20_currency}} + } + }); + } +} + +create_account(1){ + create{ + network = {"network":"Testnet", "blockchain":"Optimism"}; + key = generate_key({"curve_type": "secp256k1"}); + account = derive({ + "network_identifier": {{network}}, + "public_key": {{key.public_key}} + }); + + // If the account is not saved, the key will be lost! + save_account({ + "account_identifier": {{account.account_identifier}}, + "keypair": {{key}} + }); + } +} + +simple_transfer_erc20(1){ + transfer{ + transfer.network = {"network":"Testnet", "blockchain":"Optimism"}; + op_currency = {"symbol":"ETH", "decimals":18}; + + currency = {"symbol":"symbol", "decimals":18, "metadata": {"contractAddress": "0x9A4240883d1b4b82f8E9F21bEdD1b95Fb5176e4d"}}; + sender = find_balance({ + "minimum_balance":{ + "value": "10000000000000000", // 0.01 OP + "currency": {{currency}} + } + }); + unused = find_balance({ + "account_identifier": {{sender.account_identifier}}, + "minimum_balance":{ + "value": "10000000000000000", // 0.01 ETH + "currency": {{op_currency}} + } + }); + + // Set the recipient_amount as some value <= sender.balance-max_fee + max_fee = "4725000000000000"; // 0.004725 ETH + available_amount = {{sender.balance.value}} - {{max_fee}}; + recipient_amount = random_number({"minimum": "1", "maximum": {{available_amount}}}); + print_message({"recipient_amount":{{recipient_amount}}}); + + // Find recipient and construct operations + sender_amount = 0 - {{recipient_amount}}; + recipient = find_balance({ + "not_account_identifier":[{{sender.account_identifier}}], + "minimum_balance":{ + "value": "0", + "currency": {{currency}} + }, + "create_limit": 100, + "create_probability": 50 + }); + transfer.confirmation_depth = "1"; + transfer.operations = [ + { + "operation_identifier":{"index":0}, + "type":"PAYMENT", + "account":{{sender.account_identifier}}, + "amount":{ + "value":{{sender_amount}}, + "currency":{{currency}} + } + }, + { + "operation_identifier":{"index":1}, + "related_operations":[{"index":0}], + "type":"PAYMENT", + "account":{{recipient.account_identifier}}, + "amount":{ + "value":{{recipient_amount}}, + "currency":{{currency}} + } + } + ]; + } +} diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..5c93a0c --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Copyright 2022 Coinbase, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Start a node with default as ropsten chain. +export NETWORK=${NETWORK:-testnet} + +if [ "${NETWORK}" == "mainnet" ] || [ "${NETWORK}" == "MAINNET" ]; then + exec /app/geth --config=/app/geth.toml --gcmode=archive +else + exec /app/geth --ropsten --config=/app/geth.toml --gcmode=archive +fi \ No newline at end of file diff --git a/geth.toml b/geth.toml new file mode 100644 index 0000000..fd87f3a --- /dev/null +++ b/geth.toml @@ -0,0 +1,17 @@ +[Eth] +SyncMode = "full" + +[Node] +DataDir = "/data" +NoUSB = true +HTTPHost = "0.0.0.0" +HTTPPort = 8545 +HTTPVirtualHosts = ["*"] +GraphQLVirtualHosts = ["*"] +HTTPModules = ["eth", "debug", "admin", "txpool"] +IPCPath = "" + +[Node.HTTPTimeouts] +ReadTimeout = 120000000000 +WriteTimeout = 120000000000 +IdleTimeout = 120000000000 diff --git a/tokenList.json b/tokenList.json new file mode 100644 index 0000000..f47faf7 --- /dev/null +++ b/tokenList.json @@ -0,0 +1,16 @@ +{ + "Mainnet" : { + "0x4200000000000000000000000000000000000042": true, + "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1": true, + "0x94b008aa00579c1307b0ef2c499ad98a8ce58e58": true, + "0x68f180fcce6836688e9084f035309e29bf0a2095": true, + "0x7f5c764cbc14f9669b88837ca1490cca17c31607": true + }, + "Testnet" : { + "0x4200000000000000000000000000000000000042": true, + "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1": true, + "0x853eb4ba5d0ba2b77a0a5329fd2110d5ce149ece": true, + "0xe0a592353e81a94db6e3226fd4a99f881751776a": true, + "0x7e07e15d2a87a24492740d16f5bdf58c16db0c4e": true + } +} \ No newline at end of file diff --git a/utils/call_tracer.js b/utils/call_tracer.js new file mode 100644 index 0000000..4c0fa6a --- /dev/null +++ b/utils/call_tracer.js @@ -0,0 +1,271 @@ +// Copyright 2017 The go-ethereum Authors +// This file is part of the go-ethereum library. +// +// The go-ethereum library is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// The go-ethereum library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the go-ethereum library. If not, see . + +// callTracer is a full blown transaction tracer that extracts and reports all +// the internal calls made by a transaction, along with any useful information. +{ + // callstack is the current recursive call stack of the EVM execution. + callstack: [{}], + + // descended tracks whether we've just descended from an outer transaction into + // an inner call. + descended: false, + + // step is invoked for every opcode that the VM executes. + step: function(log, db) { + // Capture any errors immediately + var error = log.getError(); + if (error !== undefined) { + this.fault(log, db); + return; + } + // We only care about system opcodes, faster if we pre-check once + var syscall = (log.op.toNumber() & 0xf0) == 0xf0; + if (syscall) { + var op = log.op.toString(); + } + // If a new contract is being created, add to the call stack + if (syscall && (op == 'CREATE' || op == "CREATE2")) { + var inOff = log.stack.peek(1).valueOf(); + var inEnd = inOff + log.stack.peek(2).valueOf(); + + // Assemble the internal call report and store for completion + var call = { + type: op, + from: toHex(log.contract.getAddress()), + input: toHex(log.memory.slice(inOff, inEnd)), + gasIn: log.getGas(), + gasCost: log.getCost(), + value: '0x' + log.stack.peek(0).toString(16) + }; + this.callstack.push(call); + this.descended = true + return; + } + // If a contract is being self destructed, gather that as a subcall too + if (syscall && op == 'SELFDESTRUCT') { + var left = this.callstack.length; + if (this.callstack[left-1].calls === undefined) { + this.callstack[left-1].calls = []; + } + this.callstack[left-1].calls.push({ + type: op, + from: toHex(log.contract.getAddress()), + to: toHex(toAddress(log.stack.peek(0).toString(16))), + gasIn: log.getGas(), + gasCost: log.getCost(), + value: '0x' + db.getBalance(log.contract.getAddress()).toString(16) + }); + return + } + // If a new method invocation is being done, add to the call stack + if (syscall && (op == 'CALL' || op == 'CALLCODE' || op == 'DELEGATECALL' || op == 'STATICCALL')) { + var to = toAddress(log.stack.peek(1).toString(16)); + + // We don't skip any pre-compile invocations unlike the official + // geth tracer. This can silence meaningful transfers. + // if (isPrecompiled(to)) { + // return + // } + + var off = (op == 'DELEGATECALL' || op == 'STATICCALL' ? 0 : 1); + + var inOff = log.stack.peek(2 + off).valueOf(); + var inEnd = inOff + log.stack.peek(3 + off).valueOf(); + + // Assemble the internal call report and store for completion + var call = { + type: op, + from: toHex(log.contract.getAddress()), + to: toHex(to), + input: toHex(log.memory.slice(inOff, inEnd)), + gasIn: log.getGas(), + gasCost: log.getCost(), + outOff: log.stack.peek(4 + off).valueOf(), + outLen: log.stack.peek(5 + off).valueOf() + }; + if (op != 'DELEGATECALL' && op != 'STATICCALL') { + call.value = '0x' + log.stack.peek(2).toString(16); + } + this.callstack.push(call); + this.descended = true + return; + } + // If we've just descended into an inner call, retrieve it's true allowance. We + // need to extract if from within the call as there may be funky gas dynamics + // with regard to requested and actually given gas (2300 stipend, 63/64 rule). + if (this.descended) { + if (log.getDepth() >= this.callstack.length) { + this.callstack[this.callstack.length - 1].gas = log.getGas(); + } else { + // TODO(karalabe): The call was made to a plain account. We currently don't + // have access to the true gas amount inside the call and so any amount will + // mostly be wrong since it depends on a lot of input args. Skip gas for now. + } + this.descended = false; + } + // If an existing call is returning, pop off the call stack + if (syscall && op == 'REVERT') { + this.callstack[this.callstack.length - 1].error = "execution reverted"; + return; + } + if (log.getDepth() == this.callstack.length - 1) { + // Pop off the last call and get the execution results + var call = this.callstack.pop(); + + if (call.type == 'CREATE' || call.type == "CREATE2") { + // If the call was a CREATE, retrieve the contract address and output code + call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost - log.getGas()).toString(16); + delete call.gasIn; delete call.gasCost; + + var ret = log.stack.peek(0); + if (!ret.equals(0)) { + call.to = toHex(toAddress(ret.toString(16))); + call.output = toHex(db.getCode(toAddress(ret.toString(16)))); + } else if (call.error === undefined) { + call.error = "internal failure"; // TODO(karalabe): surface these faults somehow + } + } else { + // If the call was a contract call, retrieve the gas usage and output + if (call.gas !== undefined) { + call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost + call.gas - log.getGas()).toString(16); + } + var ret = log.stack.peek(0); + if (!ret.equals(0)) { + call.output = toHex(log.memory.slice(call.outOff, call.outOff + call.outLen)); + } else if (call.error === undefined) { + call.error = "internal failure"; // TODO(karalabe): surface these faults somehow + } + delete call.gasIn; delete call.gasCost; + delete call.outOff; delete call.outLen; + } + if (call.gas !== undefined) { + call.gas = '0x' + bigInt(call.gas).toString(16); + } + // Inject the call into the previous one + var left = this.callstack.length; + if (this.callstack[left-1].calls === undefined) { + this.callstack[left-1].calls = []; + } + this.callstack[left-1].calls.push(call); + } + }, + + // fault is invoked when the actual execution of an opcode fails. + fault: function(log, db) { + // If the topmost call already reverted, don't handle the additional fault again + if (this.callstack[this.callstack.length - 1].error !== undefined) { + return; + } + // Pop off the just failed call + var call = this.callstack.pop(); + call.error = log.getError(); + + // Consume all available gas and clean any leftovers + if (call.gas !== undefined) { + call.gas = '0x' + bigInt(call.gas).toString(16); + call.gasUsed = call.gas + } + delete call.gasIn; delete call.gasCost; + delete call.outOff; delete call.outLen; + + // Flatten the failed call into its parent + var left = this.callstack.length; + if (left > 0) { + if (this.callstack[left-1].calls === undefined) { + this.callstack[left-1].calls = []; + } + this.callstack[left-1].calls.push(call); + return; + } + // Last call failed too, leave it in the stack + this.callstack.push(call); + }, + + // result is invoked when all the opcodes have been iterated over and returns + // the final result of the tracing. + result: function(ctx, db) { + // Handle the case where there are no traces on L2 (ex: when deploying non-whitelisted contracts) + var value = ctx.value; + if (value === undefined) { + value = '0x0'; + } else { + value = '0x' + value.toString(16); + } + var from = ctx.from; + var to = ctx.to; + if (from !== undefined) { + from = toHex(from); + } + if (to !== undefined) { + to = toHex(to); + } + + var result = { + type: ctx.type, + from: from, + to: to, + value: value, + gas: '0x' + bigInt(ctx.gas).toString(16), + gasUsed: '0x' + bigInt(ctx.gasUsed).toString(16), + input: toHex(ctx.input), + output: toHex(ctx.output), + time: ctx.time, + }; + if (this.callstack[0].calls !== undefined) { + result.calls = this.callstack[0].calls; + } + if (this.callstack[0].error !== undefined) { + result.error = this.callstack[0].error; + } else if (ctx.error !== undefined) { + result.error = ctx.error; + } + if (result.error !== undefined && (result.error !== "execution reverted" || result.output ==="0x")) { + delete result.output; + } + return this.finalize(result); + }, + + // finalize recreates a call object using the final desired field oder for json + // serialization. This is a nicety feature to pass meaningfully ordered results + // to users who don't interpret it, just display it. + finalize: function(call) { + var sorted = { + type: call.type, + from: call.from, + to: call.to, + value: call.value, + gas: call.gas, + gasUsed: call.gasUsed, + input: call.input, + output: call.output, + error: call.error, + time: call.time, + calls: call.calls, + } + for (var key in sorted) { + if (sorted[key] === undefined) { + delete sorted[key]; + } + } + if (sorted.calls !== undefined) { + for (var i=0; i Date: Thu, 26 Jan 2023 17:03:39 -0500 Subject: [PATCH 05/18] fix: github actions and targets --- .github/workflows/lints.yaml | 27 +++++++ .github/workflows/rosetta-validation.yaml | 56 ++++++++++++++ .github/workflows/tests.yaml | 17 +++++ Makefile | 93 ++++++++++++++++++----- app/client.go | 2 +- go.mod | 4 +- go.sum | 8 -- handlers/{ops.go => handlers.go} | 0 main.go | 39 ---------- 9 files changed, 179 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/lints.yaml create mode 100644 .github/workflows/rosetta-validation.yaml create mode 100644 .github/workflows/tests.yaml rename handlers/{ops.go => handlers.go} (100%) delete mode 100644 main.go diff --git a/.github/workflows/lints.yaml b/.github/workflows/lints.yaml new file mode 100644 index 0000000..33a78c3 --- /dev/null +++ b/.github/workflows/lints.yaml @@ -0,0 +1,27 @@ +name: CI + +on: [push] + +env: + go_version: 1.16 + GO111MODULE: on + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.go_version }} + - uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --timeout 3m + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + version: latest + - run: make format diff --git a/.github/workflows/rosetta-validation.yaml b/.github/workflows/rosetta-validation.yaml new file mode 100644 index 0000000..293df6f --- /dev/null +++ b/.github/workflows/rosetta-validation.yaml @@ -0,0 +1,56 @@ +name: Rosetta Validation + +on: [push] + +env: + go_version: 1.16 + GO111MODULE: on + +jobs: + rosetta-validation: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v3 + + - name: Start a private ethereum network + uses: ./.github/actions/geth + id: geth + + - name: Sleep for 20 seconds + run: sleep 20s + shell: bash + + - name: Get latest block from geth node + run: | + curl -X POST "http://127.0.0.1:8546" --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", true],"id":1}' + shell: bash + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install web3 + + - name: deploy erc20 USDC + run: .github/scripts/init_erc20.sh + shell: bash + + - name: Get erc20 infos + run: python .github/scripts/contract_infos.py + shell: bash + + - name: Populate transactions + run: python .github/scripts/populate_txns.py + shell: bash + + - name: Start Rosetta Server + run: .github/scripts/setup.sh + shell: bash + + - name: Run Check:construction test + run: .github/scripts/construction.sh + shell: bash + + - name: Run Check:data test + run: .github/scripts/cli.sh + shell: bash \ No newline at end of file diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..b65ce20 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,17 @@ +name: CI + +on: [push] + +env: + go_version: 1.16 + GO111MODULE: on + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.go_version }} + - run: make test diff --git a/Makefile b/Makefile index 33ead0d..f4c0359 100644 --- a/Makefile +++ b/Makefile @@ -5,49 +5,108 @@ include .env PWD=$(shell pwd) NOFILE=100000 -all: clean build test lint +# Test all packages +GO_PACKAGES=./... +TEST_SCRIPT=go test ${GO_PACKAGES} +LINT_CONFIG=.golangci.yml +GOIMPORTS_INSTALL=go install golang.org/x/tools/cmd/goimports@latest +GOIMPORTS_CMD=goimports +LINT_SETTINGS=golint,misspell,gocyclo,gocritic,whitespace,goconst,gocognit,bodyclose,unconvert,lll,unparam +GOLINES_INSTALL=go install github.com/segmentio/golines@latest +GOLINES_CMD=golines +# Run the full pipeline +all: clean format build test lint +.PHONY: \ + test \ + tests \ + format \ + lint \ + build \ + clean + +# Clean up built binaries clean: rm -rf bin/op-rosetta +format: + gofmt -s -w -l . + +# Build the `op-rosetta` binary build: env GO111MODULE=on go build -o bin/op-rosetta ./cmd -test: +# Comprehensive tests +test: tests +tests: unit-tests integration-tests +unit-tests: go test -v ./... +integration-tests: config-validation +config-validation: run-optimism-mainnet-validate-config run-optimism-goerli-validate-config +# TODO: Add the `check:data` command to the pipeline +# TODO: Requires node env var configuration in the github repository for the actions to run tests successfully +check-data: run-optimism-mainnet-data-check run-optimism-goerli-data-check + +# Run the golangci-lint linter lint: golangci-lint run -E asciicheck,goimports,misspell ./... -.PHONY: \ - test \ - lint \ - build -# Runs an instance of `op-rosetta` configured for Optimism Mainnet -run-optimism-mainnet: - make build \ +################################################################################## +## GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI ## +################################################################################## + +# Runs rosetta-cli configuration:validate against the optimism goerli configuration +run-optimism-goerli-validate-config: + ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli configuration:validate configs/optimism/goerli.json + +# Runs the rosetta-cli check:data command with the optimism goerli configuration +run-optimism-goerli-data-check: + ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:data configs/optimism/goerli.json + +# Runs an instance of `op-rosetta` configured for Optimism Goerli +# For the genesis block hash, see: +# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go#L49 +run-optimism-goerli: CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \ MODE=ONLINE \ PORT=8080 \ BLOCKCHAIN=Optimism \ - NETWORK=Mainnet \ + NETWORK=Goerli \ + GETH=${OPTIMISM_GOERLI_NODE} \ ENABLE_TRACE_CACHE=true \ ENABLE_GETH_TRACER=true \ - GETH=${OPTIMISM_MAINNET_NODE} \ - GENESIS_BLOCK_HASH=0xa89b19033c8b43365e244f425a7e4acb5bae21d1893e1be0eb8cddeb29950d72 \ + GENESIS_BLOCK_HASH=0x0f783549ea4313b784eadd9b8e8a69913b368b7366363ea814d7707ac505175f \ bin/op-rosetta -# Runs an instance of `op-rosetta` configured for Optimism Goerli -run-optimism-goerli: +##################################################################################### +## MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET MAINNET ## +##################################################################################### + +# Runs rosetta-cli configuration:validate against the optimism mainnet configuration +run-optimism-mainnet-validate-config: + ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli configuration:validate configs/optimism/mainnet.json + +# Runs the rosetta-cli check:data command with the optimism mainnet configuration +run-optimism-mainnet-data-check: + ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:data configs/optimism/mainnet.json + + +# TODO: Set the GENESIS_BLOCK_HASH value for this command +# Runs an instance of `op-rosetta` configured for Optimism Mainnet +# For the genesis block hash, see: +# https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go +run-optimism-mainnet: + make build \ CHAIN_CONFIG='{ "chainId": 10, "terminalTotalDifficultyPassed": true }' \ MODE=ONLINE \ PORT=8080 \ BLOCKCHAIN=Optimism \ - NETWORK=Goerli \ - GETH=${OPTIMISM_GOERLI_NODE} \ + NETWORK=Mainnet \ ENABLE_TRACE_CACHE=true \ ENABLE_GETH_TRACER=true \ - GENESIS_BLOCK_HASH=0x0f783549ea4313b784eadd9b8e8a69913b368b7366363ea814d7707ac505175f \ + GETH=${OPTIMISM_MAINNET_NODE} \ + GENESIS_BLOCK_HASH= \ bin/op-rosetta diff --git a/app/client.go b/app/client.go index 8c65400..a696b93 100644 --- a/app/client.go +++ b/app/client.go @@ -75,7 +75,7 @@ func (c *OpClient) ParseOps( ops = append(ops, feeOps...) ops = append(ops, handlers.MintOps(tx, len(ops))...) - ops = append(ops, handlers.BurnOps(tx, len(ops))...) + // ops = append(ops, handlers.BurnOps(tx, len(ops))...) traceOps := services.TraceOps(tx.Trace, len(ops)) ops = append(ops, traceOps...) diff --git a/go.mod b/go.mod index 4474c22..92f9029 100644 --- a/go.mod +++ b/go.mod @@ -54,8 +54,8 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/tyler-smith/go-bip39 v1.0.2 // indirect github.com/urfave/cli v1.22.12 - golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e // indirect - golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect + golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect + golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect diff --git a/go.sum b/go.sum index 2f3cb4b..2ec620c 100644 --- a/go.sum +++ b/go.sum @@ -106,7 +106,6 @@ github.com/consensys/gnark-crypto v0.5.3/go.mod h1:hOdPlWQV1gDLp7faZVeg8Y0iEPFaO github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= @@ -403,7 +402,6 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -433,10 +431,7 @@ github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZL github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -<<<<<<< HEAD -======= github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c= ->>>>>>> main github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.2.0/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -448,10 +443,7 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -<<<<<<< HEAD -======= github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= ->>>>>>> main github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/supranational/blst v0.3.8-0.20220526154634-513d2456b344/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw= github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY= diff --git a/handlers/ops.go b/handlers/handlers.go similarity index 100% rename from handlers/ops.go rename to handlers/handlers.go diff --git a/main.go b/main.go deleted file mode 100644 index 5cd636b..0000000 --- a/main.go +++ /dev/null @@ -1,39 +0,0 @@ -package main - -import ( - "log" - - "github.com/coinbase/rosetta-geth-sdk/types" - "github.com/coinbase/rosetta-geth-sdk/utils" -) - -func main() { - cfg, err := LoadConfiguration() - if err != nil { - log.Fatalf("unable to load configuration: %v", err) - } - - t := types.LoadTypes() - var ots []string - for _, ot := range t.OperationTypes { - if ot == types.MinerRewardOpType || ot == types.UncleRewardOpType { - // Optimism does not have miner or uncle reward type ops - continue - } - ots = append(ots, ot) - } - ots = append(ots, types.InvalidOpType) - ots = append(ots, MintOpType) - // TODO(inphi): add BurnOpType - t.OperationTypes = ots - - client, err := NewOpClient(cfg) - if err != nil { - log.Fatalf("cannot initialize client: %v", err) - } - - err = utils.BootStrap(cfg, t, types.Errors, client) - if err != nil { - log.Fatalf("unable to bootstrap Rosetta server: %v", err) - } -} From ba8dc8d44557001bd1f8dcbb139ed27ddb50b9a8 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:09:43 -0500 Subject: [PATCH 06/18] fix: bump go version github actions --- .github/workflows/lints.yaml | 2 +- .github/workflows/rosetta-validation.yaml | 2 +- .github/workflows/tests.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lints.yaml b/.github/workflows/lints.yaml index 33a78c3..6f44e39 100644 --- a/.github/workflows/lints.yaml +++ b/.github/workflows/lints.yaml @@ -3,7 +3,7 @@ name: CI on: [push] env: - go_version: 1.16 + go_version: 1.19 GO111MODULE: on jobs: diff --git a/.github/workflows/rosetta-validation.yaml b/.github/workflows/rosetta-validation.yaml index 293df6f..b33442f 100644 --- a/.github/workflows/rosetta-validation.yaml +++ b/.github/workflows/rosetta-validation.yaml @@ -3,7 +3,7 @@ name: Rosetta Validation on: [push] env: - go_version: 1.16 + go_version: 1.19 GO111MODULE: on jobs: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b65ce20..68dda2b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -3,7 +3,7 @@ name: CI on: [push] env: - go_version: 1.16 + go_version: 1.19 GO111MODULE: on jobs: From 5926e5706c87e0bc803679a2bc0a143374e69c92 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:15:56 -0500 Subject: [PATCH 07/18] fix: sourcing env --- .github/workflows/tests.yaml | 1 + Makefile | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 68dda2b..dbd915a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,4 +14,5 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ env.go_version }} + - run: touch .env - run: make test diff --git a/Makefile b/Makefile index f4c0359..36040a3 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ # Load in the .env file -include .env +# include .env +ifneq ("$(wildcard $(.env))","") + include .env +endif # General Config PWD=$(shell pwd) From f864483680567aa3efed1511826ce84660238c65 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:21:45 -0500 Subject: [PATCH 08/18] fix: install rosetta-cli --- .github/scripts/cli.sh | 9 +++++++++ .github/workflows/lints.yaml | 2 +- .github/workflows/tests.yaml | 4 +++- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100755 .github/scripts/cli.sh diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh new file mode 100755 index 0000000..18b5af8 --- /dev/null +++ b/.github/scripts/cli.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# downloading cli +echo "Downloading rosetta-cli..." +curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s +echo "rosetta-cli downloaded" + +# echo "start check:data" +# ./bin/rosetta-cli --configuration-file examples/ethereum/rosetta-cli-conf/devnet/config.json check:data --start-block 0 diff --git a/.github/workflows/lints.yaml b/.github/workflows/lints.yaml index 6f44e39..8bfb84c 100644 --- a/.github/workflows/lints.yaml +++ b/.github/workflows/lints.yaml @@ -1,4 +1,4 @@ -name: CI +name: lints on: [push] diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index dbd915a..44dbc70 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,5 +14,7 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ env.go_version }} - - run: touch .env + - name: Run Check:data test + run: .github/scripts/cli.sh + shell: bash - run: make test From f6644e953edbd1e3133ab7a329521f4f1ebd2316 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:25:56 -0500 Subject: [PATCH 09/18] fix: makefile :sparkles: --- .github/workflows/rosetta-validation.yaml | 1 - Makefile | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rosetta-validation.yaml b/.github/workflows/rosetta-validation.yaml index b33442f..635e691 100644 --- a/.github/workflows/rosetta-validation.yaml +++ b/.github/workflows/rosetta-validation.yaml @@ -12,7 +12,6 @@ jobs: timeout-minutes: 20 steps: - uses: actions/checkout@v3 - - name: Start a private ethereum network uses: ./.github/actions/geth id: geth diff --git a/Makefile b/Makefile index 36040a3..2305910 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,4 @@ # Load in the .env file -# include .env ifneq ("$(wildcard $(.env))","") include .env endif @@ -32,9 +31,14 @@ all: clean format build test lint clean: rm -rf bin/op-rosetta +# Formatting with gofmt format: gofmt -s -w -l . +# Run the golangci-lint linter +lint: + golangci-lint run -E asciicheck,goimports,misspell ./... + # Build the `op-rosetta` binary build: env GO111MODULE=on go build -o bin/op-rosetta ./cmd @@ -47,14 +51,13 @@ unit-tests: integration-tests: config-validation config-validation: run-optimism-mainnet-validate-config run-optimism-goerli-validate-config +# TODO: Add the `check:construction` command to the pipeline +check-construction: run-optimism-mainnet-construction-check run-optimism-goerli-construction-check + # TODO: Add the `check:data` command to the pipeline # TODO: Requires node env var configuration in the github repository for the actions to run tests successfully check-data: run-optimism-mainnet-data-check run-optimism-goerli-data-check -# Run the golangci-lint linter -lint: - golangci-lint run -E asciicheck,goimports,misspell ./... - ################################################################################## ## GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI GOERLI ## @@ -68,6 +71,10 @@ run-optimism-goerli-validate-config: run-optimism-goerli-data-check: ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:data configs/optimism/goerli.json +# Runs the rosetta-cli check:construction command with the optimism goerli configuration +run-optimism-goerli-construction-check: + ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json rosetta-cli check:construction configs/optimism/goerli.json + # Runs an instance of `op-rosetta` configured for Optimism Goerli # For the genesis block hash, see: # https://github.com/ethereum-optimism/optimism/blob/5e8bc3d5b4f36f0192b22b032e25b09f23cd0985/op-node/chaincfg/chains.go#L49 @@ -95,6 +102,9 @@ run-optimism-mainnet-validate-config: run-optimism-mainnet-data-check: ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:data configs/optimism/mainnet.json +# Runs the rosetta-cli check:construction command with the optimism mainnet configuration +run-optimism-mainnet-construction-check: + ROSETTA_CONFIGURATION_FILE=configs/optimism/mainnet.json rosetta-cli check:construction configs/optimism/mainnet.json # TODO: Set the GENESIS_BLOCK_HASH value for this command # Runs an instance of `op-rosetta` configured for Optimism Mainnet From 3ca0ee3b45032ea8912a7840f4fbbbad6b0dd951 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:33:48 -0500 Subject: [PATCH 10/18] fix: testing ci :recycle: --- .github/workflows/rosetta-validation.yaml | 3 ++- .github/workflows/tests.yaml | 7 ++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rosetta-validation.yaml b/.github/workflows/rosetta-validation.yaml index 635e691..07b53dc 100644 --- a/.github/workflows/rosetta-validation.yaml +++ b/.github/workflows/rosetta-validation.yaml @@ -1,6 +1,7 @@ name: Rosetta Validation -on: [push] +# on: [push] + env: go_version: 1.19 diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 44dbc70..c0c2651 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -1,4 +1,4 @@ -name: CI +name: tests on: [push] @@ -14,7 +14,4 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ env.go_version }} - - name: Run Check:data test - run: .github/scripts/cli.sh - shell: bash - - run: make test + - run: .github/scripts/cli.sh && make test From 5ea57b79a635399c682087473637442b46d87786 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:35:47 -0500 Subject: [PATCH 11/18] fix: copy rosetta-cli over :zap: --- .github/scripts/cli.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index 18b5af8..5639307 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -5,5 +5,7 @@ echo "Downloading rosetta-cli..." curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s echo "rosetta-cli downloaded" +cp ./bin/rosetta-cli ./ + # echo "start check:data" # ./bin/rosetta-cli --configuration-file examples/ethereum/rosetta-cli-conf/devnet/config.json check:data --start-block 0 From 74fe0ab3ad843276806212132489b99b841a2e49 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:38:04 -0500 Subject: [PATCH 12/18] fix: copy rosetta-cli over :zap: --- .github/scripts/cli.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index 5639307..5d2152a 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -5,7 +5,9 @@ echo "Downloading rosetta-cli..." curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s echo "rosetta-cli downloaded" +echo "Copying rosetta-cli to root..." cp ./bin/rosetta-cli ./ +echo "Rosetta cli location: $(which rosetta-cli)" # echo "start check:data" # ./bin/rosetta-cli --configuration-file examples/ethereum/rosetta-cli-conf/devnet/config.json check:data --start-block 0 From d6db0461f97ecde25829fdd5ab8a227f6e35df26 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:41:25 -0500 Subject: [PATCH 13/18] fix: copy rosetta-cli over :zap: --- .github/scripts/cli.sh | 2 +- .github/workflows/tests.yaml | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index 5d2152a..ea0c1d7 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -6,7 +6,7 @@ curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts echo "rosetta-cli downloaded" echo "Copying rosetta-cli to root..." -cp ./bin/rosetta-cli ./ +mv ./bin/rosetta-cli ./ echo "Rosetta cli location: $(which rosetta-cli)" # echo "start check:data" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c0c2651..91606c8 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -14,4 +14,7 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ env.go_version }} - - run: .github/scripts/cli.sh && make test + - name: Install rosetta-cli + run: .github/scripts/cli.sh + - name: Run Tests + run: make test From 4fb3f23491430fd67c5afeb15dfd5be3e0fa7850 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:43:30 -0500 Subject: [PATCH 14/18] fix: copy rosetta-cli over :zap: --- .github/scripts/cli.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index ea0c1d7..c7d1b3b 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -4,9 +4,11 @@ echo "Downloading rosetta-cli..." curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s echo "rosetta-cli downloaded" +./bin/rosetta-cli --version echo "Copying rosetta-cli to root..." mv ./bin/rosetta-cli ./ +ls -la echo "Rosetta cli location: $(which rosetta-cli)" # echo "start check:data" From 1dcdf8c5b2f2b89b472b3e2e7b8b27d37a3011be Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:47:45 -0500 Subject: [PATCH 15/18] fix: cli script :gear: --- .github/scripts/cli.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index c7d1b3b..14fe402 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -4,11 +4,12 @@ echo "Downloading rosetta-cli..." curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s echo "rosetta-cli downloaded" -./bin/rosetta-cli --version +./bin/rosetta-cli version echo "Copying rosetta-cli to root..." mv ./bin/rosetta-cli ./ -ls -la +chmod +x ./rosetta-cli +rosetta-cli version echo "Rosetta cli location: $(which rosetta-cli)" # echo "start check:data" From 270f0af9f3acb43c97427cc5eb97957143786ae1 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Thu, 26 Jan 2023 17:49:27 -0500 Subject: [PATCH 16/18] fix: source rosetta-cli --- .github/scripts/cli.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/scripts/cli.sh b/.github/scripts/cli.sh index 14fe402..fb021b8 100755 --- a/.github/scripts/cli.sh +++ b/.github/scripts/cli.sh @@ -9,6 +9,7 @@ echo "rosetta-cli downloaded" echo "Copying rosetta-cli to root..." mv ./bin/rosetta-cli ./ chmod +x ./rosetta-cli +source ./ rosetta-cli version echo "Rosetta cli location: $(which rosetta-cli)" From 50ff3944e0dc8dd3f927a55059edae3631aff3a9 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Fri, 27 Jan 2023 09:07:02 -0500 Subject: [PATCH 17/18] fix: github actions with custom scripts :construction: --- .github/scripts/check-data.sh | 5 ++++ .github/scripts/validate-goerli-config.sh | 5 ++++ .../workflows/{tests.yaml => unit-tests.yaml} | 8 ++---- .github/workflows/validate-configs.yaml | 28 +++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 .github/scripts/check-data.sh create mode 100644 .github/scripts/validate-goerli-config.sh rename .github/workflows/{tests.yaml => unit-tests.yaml} (64%) create mode 100644 .github/workflows/validate-configs.yaml diff --git a/.github/scripts/check-data.sh b/.github/scripts/check-data.sh new file mode 100644 index 0000000..8127554 --- /dev/null +++ b/.github/scripts/check-data.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +./.github/scripts/cli.sh + +ROSETTA_CONFIGURATION_FILE=configs/optimism/goerli.json ./bin/rosetta-cli check:data configs/optimism/goerli.json diff --git a/.github/scripts/validate-goerli-config.sh b/.github/scripts/validate-goerli-config.sh new file mode 100644 index 0000000..112d67b --- /dev/null +++ b/.github/scripts/validate-goerli-config.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +./.github/scripts/cli.sh + +./bin/rosetta-cli configuration:validate configs/optimism/goerli.json diff --git a/.github/workflows/tests.yaml b/.github/workflows/unit-tests.yaml similarity index 64% rename from .github/workflows/tests.yaml rename to .github/workflows/unit-tests.yaml index 91606c8..01a32f6 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/unit-tests.yaml @@ -1,4 +1,4 @@ -name: tests +name: unit tests on: [push] @@ -14,7 +14,5 @@ jobs: - uses: actions/setup-go@v3 with: go-version: ${{ env.go_version }} - - name: Install rosetta-cli - run: .github/scripts/cli.sh - - name: Run Tests - run: make test + - name: run unit tests + run: make unit-tests diff --git a/.github/workflows/validate-configs.yaml b/.github/workflows/validate-configs.yaml new file mode 100644 index 0000000..69dc5c2 --- /dev/null +++ b/.github/workflows/validate-configs.yaml @@ -0,0 +1,28 @@ +name: validate config files + +on: [push] + +env: + go_version: 1.19 + GO111MODULE: on + +jobs: + goerli-configs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.go_version }} + - name: validate optimism goerli configs + run: .github/scripts/validate-goerli-config.sh + shell: bash + mainnet-configs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: ${{ env.go_version }} + - name: validate optimism mainnet configs + run: echo "TODO" From f880d5e56707048089787a57631afe680e9a60b6 Mon Sep 17 00:00:00 2001 From: Andreas Bigger Date: Fri, 27 Jan 2023 09:17:23 -0500 Subject: [PATCH 18/18] fix: github actions with custom scripts :construction: --- .github/scripts/check-data.sh | 0 .github/scripts/validate-goerli-config.sh | 5 ++++- 2 files changed, 4 insertions(+), 1 deletion(-) mode change 100644 => 100755 .github/scripts/check-data.sh mode change 100644 => 100755 .github/scripts/validate-goerli-config.sh diff --git a/.github/scripts/check-data.sh b/.github/scripts/check-data.sh old mode 100644 new mode 100755 diff --git a/.github/scripts/validate-goerli-config.sh b/.github/scripts/validate-goerli-config.sh old mode 100644 new mode 100755 index 112d67b..3c93d36 --- a/.github/scripts/validate-goerli-config.sh +++ b/.github/scripts/validate-goerli-config.sh @@ -1,5 +1,8 @@ #!/bin/bash -./.github/scripts/cli.sh +echo "Downloading rosetta-cli..." +curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | sh -s +echo "rosetta-cli downloaded" +./bin/rosetta-cli version ./bin/rosetta-cli configuration:validate configs/optimism/goerli.json