Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
feat(cmd): rename EnvVars base on flag name and fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 committed Apr 18, 2024
1 parent f3a030a commit 24ec8e6
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 106 deletions.
21 changes: 10 additions & 11 deletions cmd/flags/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@ var (
Usage: "Websocket RPC endpoint of a L1 ethereum node",
Required: true,
Category: commonCategory,
EnvVars: []string{"L1_WS_ENDPOINT"},
EnvVars: []string{"L1_WS"},
}
L2WSEndpoint = &cli.StringFlag{
Name: "l2.ws",
Usage: "Websocket RPC endpoint of a L2 taiko-geth execution engine",
Required: true,
Category: commonCategory,
EnvVars: []string{"L2_WS_ENDPOINT"},
EnvVars: []string{"L2_WS"},
}
L1HTTPEndpoint = &cli.StringFlag{
Name: "l1.http",
Usage: "HTTP RPC endpoint of a L1 ethereum node",
Required: true,
Category: commonCategory,
EnvVars: []string{"L1_HTTP_ENDPOINT"},
EnvVars: []string{"L1_HTTP"},
}
L1BeaconEndpoint = &cli.StringFlag{
Name: "l1.beacon",
Usage: "HTTP RPC endpoint of a L1 beacon node",
Category: commonCategory,
EnvVars: []string{"L1_BEACON_ENDPOINT"},
EnvVars: []string{"L1_BEACON"},
}
L2HTTPEndpoint = &cli.StringFlag{
Name: "l2.http",
Usage: "HTTP RPC endpoint of a L2 taiko-geth execution engine",
Required: true,
Category: commonCategory,
EnvVars: []string{"L2_HTTP_ENDPOINT"},
EnvVars: []string{"L2_HTTP"},
}
L2AuthEndpoint = &cli.StringFlag{
Name: "l2.auth",
Usage: "Authenticated HTTP RPC endpoint of a L2 taiko-geth execution engine",
Required: true,
Category: commonCategory,
EnvVars: []string{"L2_AUTH_ENDPOINT"},
EnvVars: []string{"L2_AUTH"},
}
JWTSecret = &cli.StringFlag{
Name: "jwtSecret",
Expand All @@ -72,21 +72,21 @@ var (
Usage: "TaikoL1 contract `address`",
Required: true,
Category: commonCategory,
EnvVars: []string{"TAIKO_L1_ADDRESS"},
EnvVars: []string{"TAIKO_L1"},
}
TaikoL2Address = &cli.StringFlag{
Name: "taikoL2",
Usage: "TaikoL2 contract `address`",
Required: true,
Category: commonCategory,
EnvVars: []string{"TAIKO_L2_ADDRESS"},
EnvVars: []string{"TAIKO_L2"},
}
TaikoTokenAddress = &cli.StringFlag{
Name: "taikoToken",
Usage: "TaikoToken contract `address`",
Required: true,
Category: commonCategory,
EnvVars: []string{"TAIKO_TOKEN_ADDRESS"},
EnvVars: []string{"TAIKO_TOKEN"},
}
// Optional flags used by all client software.
// Logging
Expand All @@ -109,7 +109,7 @@ var (
Usage: "Enable metrics collection and reporting",
Category: metricsCategory,
Value: false,
EnvVars: []string{"METRICS_ENABLED"},
EnvVars: []string{"METRICS"},
}
MetricsAddr = &cli.StringFlag{
Name: "metrics.addr",
Expand Down Expand Up @@ -149,7 +149,6 @@ var (
AssignmentHookAddress = &cli.StringFlag{
Name: "assignmentHookAddress",
Usage: "Address of the AssignmentHook contract",
Required: true,
Category: commonCategory,
EnvVars: []string{"ASSIGNMENT_HOOK_ADDRESS"},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var (
Name: "blob.server",
Usage: "Blob sidecar storage server",
Category: driverCategory,
EnvVars: []string{"BLOB_SERVER_ENDPOINT"},
EnvVars: []string{"BLOB_SERVER"},
}
)

Expand Down
18 changes: 9 additions & 9 deletions cmd/flags/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ var (
// Optional flags used by proposer.
var (
// Tier fee related.
OptimisticTierFee = &cli.Uint64Flag{
OptimisticTierFee = &cli.Float64Flag{
Name: "tierFee.optimistic",
Usage: "Initial tier fee (in GWei) paid to prover to generate an optimistic proofs",
Category: proposerCategory,
EnvVars: []string{"OPTIMISTIC_TIER_FEE"},
EnvVars: []string{"TIER_FEE_OPTIMISTIC"},
}
SgxTierFee = &cli.Uint64Flag{
SgxTierFee = &cli.Float64Flag{
Name: "tierFee.sgx",
Usage: "Initial tier fee (in GWei) paid to prover to generate a SGX proofs",
Category: proposerCategory,
EnvVars: []string{"SGX_TIER_FEE"},
EnvVars: []string{"TIER_FEE_SGX"},
}
TierFeePriceBump = &cli.Uint64Flag{
Name: "tierFee.pricebump",
Expand All @@ -58,15 +58,15 @@ var (
Usage: "If nobody accepts block at initial tier fee, how many iterations to increase tier fee before giving up",
Category: proposerCategory,
Value: 3,
EnvVars: []string{"MAX_TIER_FEE_PRICE_BUMPS"},
EnvVars: []string{"TIER_FEE_MAX_PRICE_BUMPS"},
}
// Proposing epoch related.
ProposeInterval = &cli.DurationFlag{
Name: "epoch.interval",
Usage: "Time interval to propose L2 pending transactions",
Category: proposerCategory,
Value: 0,
EnvVars: []string{"PROPOSE_INTERVAL"},
EnvVars: []string{"EPOCH_INTERVAL"},
}
MinGasUsed = &cli.Uint64Flag{
Name: "epoch.minGasUsed",
Expand Down Expand Up @@ -116,14 +116,14 @@ var (
Usage: "Maximum number of transaction lists which will be proposed inside one proposing epoch",
Value: 1,
Category: proposerCategory,
EnvVars: []string{"MAX_PROPOSED_TX_LISTS_PER_EPOCH"},
EnvVars: []string{"MAX_TX_LISTS_PER_EPOCH"},
}
ProposeBlockIncludeParentMetaHash = &cli.BoolFlag{
Name: "includeParentMetaHash",
Usage: "Include parent meta hash when proposing block",
Value: false,
Category: proposerCategory,
EnvVars: []string{"PROPOSE_BLOCK_INCLUDE_PARENT_METAHASH"},
EnvVars: []string{"INCLUDE_PARENT_METAHASH"},
}
// Transaction related.
BlobAllowed = &cli.BoolFlag{
Expand All @@ -137,7 +137,7 @@ var (
Usage: "Amount you wish to tip the L1 block builder",
Value: 0,
Category: proposerCategory,
EnvVars: []string{"L1_BLOCK_BUILDER_TIP"},
EnvVars: []string{"BLOCK_BUILDER_TIP"},
}
)

Expand Down
36 changes: 18 additions & 18 deletions cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@ var (
// Optional flags used by prover.
var (
RaikoHostEndpoint = &cli.StringFlag{
Name: "raiko.hostEndpoint",
Name: "raiko.host",
Usage: "RPC endpoint of a Raiko host service",
Category: proverCategory,
EnvVars: []string{"RAIKO_HOST_ENDPOINT"},
EnvVars: []string{"RAIKO_HOST"},
}
RaikoL1Endpoint = &cli.StringFlag{
Name: "raiko.l1Endpoint",
Name: "raiko.l1",
Usage: "L1 RPC endpoint which will be sent to the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L1_ENDPOINT"},
EnvVars: []string{"RAIKO_L1"},
}
RaikoL1BeaconEndpoint = &cli.StringFlag{
Name: "raiko.l1BeaconEndpoint",
Name: "raiko.l1Beacon",
Usage: "L1 beacon RPC endpoint which will be sent to the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L1_BEACON_ENDPOINT"},
EnvVars: []string{"RAIKO_L1_BEACON"},
}
RaikoL2Endpoint = &cli.StringFlag{
Name: "raiko.l2Endpoint",
Name: "raiko.l2",
Usage: "L2 RPC endpoint which will be sent to the Raiko service",
Category: proverCategory,
EnvVars: []string{"RAIKO_L2_ENDPOINT"},
EnvVars: []string{"RAIKO_L2"},
}
StartingBlockID = &cli.Uint64Flag{
Name: "prover.startingBlockID",
Expand Down Expand Up @@ -80,7 +80,7 @@ var (
}
MinTaikoTokenBalance = &cli.Float64Flag{
Name: "prover.minTaikoTokenBalance",
Usage: "Minimum Taiko token balance (in Ether) a prover wants to keep",
Usage: "Minimum Taiko token balance without decimal a prover wants to keep",
Category: proverCategory,
Value: 0,
EnvVars: []string{"MIN_TAIKO_TOKEN_BALANCE"},
Expand All @@ -90,35 +90,35 @@ var (
Name: "minTierFee.optimistic",
Usage: "Minimum accepted fee for generating an optimistic proof",
Category: proverCategory,
EnvVars: []string{"MIN_OPTIMISTIC_TIER_FEE"},
EnvVars: []string{"MIN_TIER_FEE_OPTIMISTIC"},
}
MinSgxTierFee = &cli.Uint64Flag{
Name: "minTierFee.sgx",
Usage: "Minimum accepted fee for generating a SGX proof",
Category: proverCategory,
EnvVars: []string{"MIN_SGX_TIER_FEE"},
EnvVars: []string{"MIN_TIER_FEE_SGX"},
}
MinSgxAndZkVMTierFee = &cli.Uint64Flag{
Name: "minTierFee.sgxAndZkvm",
Usage: "Minimum accepted fee for generating a SGX + zkVM proof",
Category: proverCategory,
EnvVars: []string{"MIN_SGX_AND_ZKVM_TIER_FEE"},
EnvVars: []string{"MIN_TIER_FEE_SGX_AND_ZKVM"},
}
// Running mode
ContesterMode = &cli.BoolFlag{
Name: "mode.contester",
Usage: "Whether you want to contest wrong transitions with higher tier proofs",
Category: proverCategory,
Value: false,
EnvVars: []string{"CONTESTER_MODE"},
EnvVars: []string{"MODE_CONTESTER"},
}
// HTTP server related.
ProverHTTPServerPort = &cli.Uint64Flag{
Name: "http.port",
Usage: "Port to expose for http server",
Category: proverCategory,
Value: 9876,
EnvVars: []string{"PROVER_HTTP_SERVER_PORT"},
EnvVars: []string{"PROVER_HTTP_PORT"},
}
MaxExpiry = &cli.DurationFlag{
Name: "http.maxExpiry",
Expand All @@ -141,7 +141,7 @@ var (
Usage: "Maximum accepted slippage difference for blockID for accepting proving a block",
Value: 1024,
Category: proverCategory,
EnvVars: []string{"MAX_ACCEPTABLE_BLOCK_SLIPPAGE"},
EnvVars: []string{"BLOCK_SLIPPAGE"},
}
// Max amount of L1 blocks that can pass before block is invalid
MaxProposedIn = &cli.Uint64Flag{
Expand All @@ -153,7 +153,7 @@ var (
}
Allowance = &cli.Float64Flag{
Name: "prover.allowance",
Usage: "Amount (in Ether) to approve AssignmentHook contract for TaikoToken usage",
Usage: "Amount without decimal to approve AssignmentHook contract for TaikoToken usage",
Category: proverCategory,
EnvVars: []string{"ALLOWANCE"},
}
Expand All @@ -168,14 +168,14 @@ var (
Name: "guardianProver",
Usage: "GuardianProver contract `address`",
Category: proverCategory,
EnvVars: []string{"GUARDIAN_PROVER"},
EnvVars: []string{"GUARDIAN_PROVER"},
}
GuardianProofSubmissionDelay = &cli.DurationFlag{
Name: "guardian.submissionDelay",
Usage: "Guardian proof submission delay",
Value: 1 * time.Hour,
Category: proverCategory,
EnvVars: []string{"GUARDIAN_PROOF_SUBMISSION_DELAY"},
EnvVars: []string{"GUARDIAN_SUBMISSION_DELAY"},
}
EnableLivenessBondProof = &cli.BoolFlag{
Name: "prover.enableLivenessBondProof",
Expand Down
4 changes: 2 additions & 2 deletions cmd/flags/txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ var (
Usage: "Timeout for sending transactions. If 0 it is disabled.",
Value: 0,
Category: txmgrCategory,
EnvVars: []string{"TX_SEND_TIMEOUT"},
EnvVars: []string{"SEND_TIMEOUT"},
}
TxNotInMempoolTimeout = &cli.DurationFlag{
Name: "tx.notInMempoolTimeout",
Usage: "Timeout for aborting a tx send if the tx does not make it to the mempool.",
Value: 2 * time.Minute,
Category: txmgrCategory,
EnvVars: []string{"TX_NOT_IN_MEMPOOL_TIMEOUT"},
EnvVars: []string{"NOT_IN_MEMPOOL_TIMEOUT"},
}
ReceiptQueryInterval = &cli.DurationFlag{
Name: "tx.receiptQueryInterval",
Expand Down
48 changes: 47 additions & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import (
"crypto/rand"
"errors"
"fmt"
"math"

"io"
"math/big"
"os"
"strings"

"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/joho/godotenv"
"github.com/modern-go/reflect2"
"golang.org/x/exp/constraints"
Expand Down Expand Up @@ -109,3 +112,46 @@ func Decompress(compressedTxList []byte) ([]byte, error) {

return b, nil
}

// GWeiToWei converts gwei value to wei value.
func GWeiToWei(gwei float64) (*big.Int, error) {
if math.IsNaN(gwei) || math.IsInf(gwei, 0) {
return nil, fmt.Errorf("invalid gwei value: %v", gwei)
}

// convert float GWei value into integer Wei value
wei, _ := new(big.Float).Mul(
big.NewFloat(gwei),
big.NewFloat(params.GWei)).
Int(nil)

if wei.Cmp(abi.MaxUint256) == 1 {
return nil, errors.New("gwei value larger than max uint256")
}

return wei, nil
}

// EtherToWei converts ether value to wei value.
func EtherToWei(ether float64) (*big.Int, error) {
if math.IsNaN(ether) || math.IsInf(ether, 0) {
return nil, fmt.Errorf("invalid ether value: %v", ether)
}

// convert float GWei value into integer Wei value
wei, _ := new(big.Float).Mul(
big.NewFloat(ether),
big.NewFloat(params.GWei)).
Int(nil)

if wei.Cmp(abi.MaxUint256) == 1 {
return nil, errors.New("gwei value larger than max uint256")
}

return wei, nil
}

// WeiToEther converts wei value to ether value.
func WeiToEther(wei *big.Int) *big.Float {
return new(big.Float).Quo(new(big.Float).SetInt(wei), new(big.Float).SetInt(big.NewInt(params.Ether)))
}
Loading

0 comments on commit 24ec8e6

Please sign in to comment.