Add more flags and configs

This commit is contained in:
Ferran Borreguero 2021-10-04 09:48:12 +02:00
parent a54cec4595
commit 8fe5c5a329
11 changed files with 411 additions and 11 deletions

View file

@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"strings"
"time"
)
type Flagset struct {
@ -93,3 +94,39 @@ func (f *Flagset) IntFlag(i *IntFlag) {
})
f.set.IntVar(i.Value, i.Name, i.Default, i.Usage)
}
type SliceStringFlag struct {
Name string
Usage string
Value []string
}
func (i *SliceStringFlag) String() string {
return ""
}
func (i *SliceStringFlag) Set(value string) error {
i.Value = append(i.Value, value)
return nil
}
func (f *Flagset) SliceStringFlag(s *SliceStringFlag) {
f.addFlag(&FlagVar{
Name: s.Name,
Usage: s.Usage,
})
f.set.Var(s, s.Name, s.Usage)
}
type DurationFlag struct {
Name string
Usage string
Value *time.Duration
}
func (f *Flagset) DurationFlag(d *DurationFlag) {
f.addFlag(&FlagVar{
Name: d.Name,
Usage: d.Usage,
})
}

View file

@ -41,5 +41,10 @@ func commands() map[string]cli.CommandFactory {
UI: ui,
}, nil
},
"version": func() (cli.Command, error) {
return &VersionCommand{
UI: ui,
}, nil
},
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,61 @@
package chains
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params"
)
var BorMainnetGenesisHash = common.HexToHash("0xa9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b")
var BorMainnetChainConfig = &params.ChainConfig{
ChainID: big.NewInt(137),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(3395000),
MuirGlacierBlock: big.NewInt(3395000),
BerlinBlock: big.NewInt(14750000),
Bor: &params.BorConfig{
Period: 2,
ProducerDelay: 6,
Sprint: 64,
BackupMultiplier: 2,
ValidatorContract: "0x0000000000000000000000000000000000001000",
StateReceiverContract: "0x0000000000000000000000000000000000001001",
OverrideStateSyncRecords: map[string]int{
"14949120": 8,
"14949184": 0,
"14953472": 0,
"14953536": 5,
"14953600": 0,
"14953664": 0,
"14953728": 0,
"14953792": 0,
"14953856": 0,
},
},
}
//DefaultBorMainnet returns the Bor Mainnet network gensis block.
func DefaultBorMainnetGenesisBlock() *core.Genesis {
return &core.Genesis{
Config: BorMainnetChainConfig,
Nonce: 0,
Timestamp: 1590824836,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"),
Alloc: readPrealloc("allocs/bor_mainnet.json"),
}
}

View file

@ -0,0 +1,49 @@
package chains
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params"
)
var MumbaiGenesisHash = common.HexToHash("0x7b66506a9ebdbf30d32b43c5f15a3b1216269a1ec3a75aa3182b86176a2b1ca7")
var MumbaiChainConfig = &params.ChainConfig{
ChainID: big.NewInt(80001),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
EIP150Hash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
EIP150Block: big.NewInt(0),
EIP155Block: big.NewInt(0),
EIP158Block: big.NewInt(0),
ByzantiumBlock: big.NewInt(0),
ConstantinopleBlock: big.NewInt(0),
PetersburgBlock: big.NewInt(0),
IstanbulBlock: big.NewInt(2722000),
MuirGlacierBlock: big.NewInt(2722000),
BerlinBlock: big.NewInt(13996000),
Bor: &params.BorConfig{
Period: 2,
ProducerDelay: 6,
Sprint: 64,
BackupMultiplier: 2,
ValidatorContract: "0x0000000000000000000000000000000000001000",
StateReceiverContract: "0x0000000000000000000000000000000000001001",
},
}
func DefaultMumbaiGenesisBlock() *core.Genesis {
return &core.Genesis{
Config: MumbaiChainConfig,
Nonce: 0,
Timestamp: 1558348305,
GasLimit: 10000000,
Difficulty: big.NewInt(1),
Mixhash: common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000000000"),
Coinbase: common.HexToAddress("0x0000000000000000000000000000000000000000"),
Alloc: readPrealloc("allocs/mumbai.json"),
}
}

View file

@ -0,0 +1,27 @@
package chains
import (
"embed"
"encoding/json"
"fmt"
"github.com/ethereum/go-ethereum/core"
)
//go:embed allocs
var allocs embed.FS
func readPrealloc(filename string) core.GenesisAlloc {
f, err := allocs.Open(filename)
if err != nil {
panic(fmt.Sprintf("Could not open genesis preallocation for %s: %v", filename, err))
}
defer f.Close()
decoder := json.NewDecoder(f)
ga := make(core.GenesisAlloc)
err = decoder.Decode(&ga)
if err != nil {
panic(fmt.Sprintf("Could not parse genesis preallocation for %s: %v", filename, err))
}
return ga
}

View file

@ -33,12 +33,15 @@ type Command struct {
// Help implements the cli.Command interface
func (c *Command) Help() string {
return ""
return `Usage: bor [options]
Run the Bor server.
` + c.Flags().Help()
}
// Synopsis implements the cli.Command interface
func (c *Command) Synopsis() string {
return ""
return "Run the Bor server"
}
// Run implements the cli.Command interface

View file

@ -1,7 +1,9 @@
package server
import (
"fmt"
"strconv"
"time"
"github.com/ethereum/go-ethereum/common/fdlimit"
"github.com/ethereum/go-ethereum/eth/downloader"
@ -23,28 +25,86 @@ func boolPtr(b bool) *bool {
return &b
}
func durPtr(d time.Duration) *time.Duration {
return &d
}
type Config struct {
Chain *string
Debug *bool
LogLevel *string
DataDir *string
P2P *P2PConfig
SyncMode *string
EthStats *string
TxPool *TxPoolConfig
Sealer *SealerConfig
}
type P2PConfig struct {
MaxPeers *uint64
Bind *string
Port *uint64
MaxPeers *uint64
Bind *string
Port *uint64
NoDiscover *bool
V5Disc *bool
Bootnodes []string
BootnodesV4 []string
BootnodesV5 []string
}
type TxPoolConfig struct {
Locals []string
NoLocals *bool
Journal *string
Rejournal *time.Duration
PriceLimit *uint64
PriceBump *uint64
AccountSlots *uint64
GlobalSlots *uint64
AccountQueue *uint64
GlobalQueue *uint64
LifeTime *time.Duration
}
type SealerConfig struct {
Seal *bool
Etherbase *string
ExtraData *string
}
func DefaultConfig() *Config {
return &Config{
Chain: stringPtr("mainnet"),
Debug: boolPtr(false),
LogLevel: stringPtr("INFO"),
DataDir: stringPtr(""),
P2P: &P2PConfig{
MaxPeers: uint64Ptr(30),
Bind: stringPtr("0.0.0.0."),
Port: uint64Ptr(30303),
MaxPeers: uint64Ptr(30),
Bind: stringPtr("0.0.0.0"),
Port: uint64Ptr(30303),
NoDiscover: boolPtr(false),
V5Disc: boolPtr(false),
Bootnodes: []string{},
BootnodesV4: []string{},
BootnodesV5: []string{},
},
SyncMode: stringPtr("fast"),
EthStats: stringPtr(""),
TxPool: &TxPoolConfig{
Locals: []string{},
NoLocals: boolPtr(false),
Journal: stringPtr(""),
Rejournal: durPtr(1 * time.Hour),
PriceLimit: uint64Ptr(1),
PriceBump: uint64Ptr(10),
AccountSlots: uint64Ptr(16),
GlobalSlots: uint64Ptr(4096),
AccountQueue: uint64Ptr(64),
GlobalQueue: uint64Ptr(1024),
LifeTime: durPtr(3 * time.Hour),
},
Sealer: &SealerConfig{
Seal: boolPtr(false),
},
}
}
@ -61,7 +121,36 @@ func (c *Config) buildEth() (*ethconfig.Config, error) {
n := ethconfig.Defaults
//n.NetworkId = c.genesis.NetworkId
//n.Genesis = c.genesis.Genesis
n.SyncMode = downloader.FastSync
// txpool options
{
cfg := n.TxPool
cfg.NoLocals = *c.TxPool.NoLocals
cfg.Journal = *c.TxPool.Journal
cfg.Rejournal = *c.TxPool.Rejournal
cfg.PriceLimit = *c.TxPool.PriceLimit
cfg.PriceBump = *c.TxPool.PriceBump
cfg.AccountSlots = *c.TxPool.AccountSlots
cfg.GlobalSlots = *c.TxPool.GlobalSlots
cfg.AccountQueue = *c.TxPool.AccountQueue
cfg.GlobalQueue = *c.TxPool.GlobalQueue
cfg.Lifetime = *c.TxPool.LifeTime
}
// miner options
{
cfg := n.Miner
fmt.Println(cfg)
}
var syncMode downloader.SyncMode
switch *c.SyncMode {
case "fast":
syncMode = downloader.FastSync
default:
return nil, fmt.Errorf("sync mode '%s' not found", syncMode)
}
n.SyncMode = syncMode
n.DatabaseHandles = dbHandles
return &n, nil
}

View file

@ -3,15 +3,20 @@ package server
import "github.com/ethereum/go-ethereum/command/flagset"
func (c *Command) Flags() *flagset.Flagset {
c.cliConfig = &Config{}
c.cliConfig = DefaultConfig()
f := flagset.NewFlagSet("server")
f := flagset.NewFlagSet("")
f.BoolFlag(&flagset.BoolFlag{
Name: "debug",
Value: c.cliConfig.Debug,
Usage: "Path of the file to apply",
})
f.StringFlag(&flagset.StringFlag{
Name: "chain",
Value: c.cliConfig.Chain,
Usage: "Name of the chain to sync",
})
f.StringFlag(&flagset.StringFlag{
Name: "log-level",
Value: c.cliConfig.LogLevel,
@ -28,5 +33,34 @@ func (c *Command) Flags() *flagset.Flagset {
Usage: "File for the config file",
})
// txpool options
f.SliceStringFlag(&flagset.SliceStringFlag{
Name: "txpool.locals",
Value: c.cliConfig.TxPool.Locals,
Usage: "Comma separated accounts to treat as locals (no flush, priority inclusion)",
})
f.BoolFlag(&flagset.BoolFlag{
Name: "txpool.nolocals",
Value: c.cliConfig.TxPool.NoLocals,
Usage: "Disables price exemptions for locally submitted transactions",
})
// sealer options
f.BoolFlag(&flagset.BoolFlag{
Name: "mine",
Value: c.cliConfig.Sealer.Seal,
Usage: "",
})
f.StringFlag(&flagset.StringFlag{
Name: "miner.etherbase",
Value: c.cliConfig.Sealer.Etherbase,
Usage: "",
})
f.StringFlag(&flagset.StringFlag{
Name: "miner.extradata",
Value: c.cliConfig.Sealer.ExtraData,
Usage: "",
})
return f
}

30
command/version.go Normal file
View file

@ -0,0 +1,30 @@
package main
import (
"github.com/ethereum/go-ethereum/params"
"github.com/mitchellh/cli"
)
// VersionCommand is the command to show the version of the agent
type VersionCommand struct {
UI cli.Ui
}
// Help implements the cli.Command interface
func (c *VersionCommand) Help() string {
return `Usage: ensemble version
Display the Ensemble version`
}
// Synopsis implements the cli.Command interface
func (c *VersionCommand) Synopsis() string {
return "Display the Bor version"
}
// Run implements the cli.Command interface
func (c *VersionCommand) Run(args []string) int {
c.UI.Output(params.VersionWithMeta)
return 0
}