Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collator v3 #1

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
14f9402
wip collator v3
jwasinger Aug 17, 2021
0ad5127
moar
jwasinger Aug 18, 2021
c3a5f72
more
jwasinger Aug 18, 2021
482a7cb
wip
jwasinger Aug 18, 2021
1d35542
more
jwasinger Aug 18, 2021
7b15d9a
more
jwasinger Aug 19, 2021
9fa4bd4
builds and passes tests
jwasinger Aug 19, 2021
4f1d965
add Start/Close hooks to collator interface. add collator as field i…
jwasinger Aug 20, 2021
0feac48
move some fields in BlockState into an accessor object for read-only …
jwasinger Aug 22, 2021
46995fc
rename environment.coinbase -> environment.etherbase
jwasinger Aug 22, 2021
8638f09
set worker.current before call to commit
jwasinger Aug 23, 2021
a714ff6
remove uneccessary copying in readonly header
jwasinger Aug 23, 2021
d8bd276
fix to interrupt handling in worker.
jwasinger Aug 23, 2021
ac2425b
make generateWork use the active collator
jwasinger Aug 23, 2021
7935044
close collator
jwasinger Aug 23, 2021
673b403
return bool based on whether RevertTransaction had an effect. fix so…
jwasinger Aug 23, 2021
3eb8108
remove uncessary explicit array copying using copy(). handle case wh…
jwasinger Aug 24, 2021
6fbe142
gofmt
jwasinger Aug 24, 2021
2c051a6
copy gasPool in environment.copy()
jwasinger Aug 24, 2021
f5f3d8c
remove ReadOnly header and have BlockState.Header() return a copy of …
jwasinger Aug 27, 2021
af70a61
don't discard the original environment's prefetcher in the collator. …
jwasinger Aug 27, 2021
11051e7
add suggestions
jwasinger Aug 28, 2021
ffb9b26
wip: custom rpc registration, custom collator config loading, collato…
jwasinger Aug 31, 2021
18aeeb2
make tests pass again
jwasinger Aug 31, 2021
1ca11f5
add collator cli flags to client
jwasinger Sep 1, 2021
1620607
remove RevertTransaction
jwasinger Sep 2, 2021
c002778
move state access as a getter on BlockState
jwasinger Sep 3, 2021
feff175
moar
jwasinger Sep 4, 2021
47492f2
no pointer to interface
jwasinger Sep 8, 2021
b099617
correct check for method signature of plugin constructor
jwasinger Sep 9, 2021
857da88
copy shouldSeal in blockState.Copy()
jwasinger Sep 10, 2021
96e6f76
add interrupt context object so plugins can poll without having to mo…
jwasinger Sep 13, 2021
5cc501d
document interface. make recommit adjustment ratio fixed.
jwasinger Sep 13, 2021
f0bef3b
fix build error
jwasinger Sep 13, 2021
8c13763
make BlockState.AddTransaction -> BlockState.AddTransactions for API …
jwasinger Sep 14, 2021
b688f81
return from AddTransactions if recommit interval has gone off, and wa…
jwasinger Sep 16, 2021
7880fef
AddTransactions stores a snapshot for every added tx
jwasinger Sep 16, 2021
ab34e15
change use of blockState.committed to prevent mutation after calling …
jwasinger Sep 16, 2021
4f04a20
make sure new blockState instance has a state snapshot for the empty …
jwasinger Sep 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/geth/main.go
Expand Up @@ -125,6 +125,9 @@ var (
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.MinerCollatorPluginEnableFlag,
utils.MinerCollatorPluginPath,
utils.MinerCollatorPluginConfigPath,
utils.NATFlag,
utils.NoDiscoverFlag,
utils.DiscoveryV5Flag,
Expand Down
22 changes: 22 additions & 0 deletions cmd/utils/flags.go
Expand Up @@ -477,6 +477,19 @@ var (
Name: "miner.noverify",
Usage: "Disable remote sealing verification",
}
MinerCollatorPluginEnableFlag = cli.BoolFlag{
Name: "miner.enablecollatorplugin",
Usage: "Enable custom miner collator",
}
MinerCollatorPluginPath = cli.StringFlag{
Name: "miner.collatorpluginfile",
Usage: "Path to collator plugin compiled as shared library",
}
MinerCollatorPluginConfigPath = cli.StringFlag{
Name: "miner.collatorpluginconfigfile",
Usage: "Path to custom collator config toml",
}

// Account settings
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Expand Down Expand Up @@ -1401,6 +1414,15 @@ func setMiner(ctx *cli.Context, cfg *miner.Config) {
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
cfg.Noverify = ctx.GlobalBool(MinerNoVerfiyFlag.Name)
}
if ctx.GlobalIsSet(MinerCollatorPluginEnableFlag.Name) {
cfg.UseCustomCollator = ctx.GlobalBool(MinerCollatorPluginEnableFlag.Name)
}
if ctx.GlobalIsSet(MinerCollatorPluginPath.Name) {
cfg.CollatorPath = ctx.GlobalString(MinerCollatorPluginPath.Name)
}
if ctx.GlobalIsSet(MinerCollatorPluginConfigPath.Name) {
cfg.CollatorConfigPath = ctx.GlobalString(MinerCollatorPluginConfigPath.Name)
}
}

func setWhitelist(ctx *cli.Context, cfg *ethconfig.Config) {
Expand Down
16 changes: 16 additions & 0 deletions core/vm/interface.go
Expand Up @@ -76,6 +76,22 @@ type StateDB interface {
ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) error
}

type StateReader interface {
GetBalance(common.Address) *big.Int
GetNonce(common.Address) uint64
GetCodeHash(common.Address) common.Hash
GetCode(common.Address) []byte
GetCodeSize(common.Address) int
GetRefund() uint64
GetCommittedState(common.Address, common.Hash) common.Hash
GetState(common.Address, common.Hash) common.Hash
HasSuicided(common.Address) bool
Exist(common.Address) bool
Empty(common.Address) bool
AddressInAccessList(addr common.Address) bool
SlotInAccessList(addr common.Address, slot common.Hash) (addressOk bool, slotOk bool)
}

// CallContext provides a basic interface for the EVM calling conventions. The EVM
// depends on this context being implemented for doing subcalls and initialising new EVM contracts.
type CallContext interface {
Expand Down
24 changes: 23 additions & 1 deletion eth/backend.go
Expand Up @@ -111,6 +111,19 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
}

var minerCollator miner.Collator
var minerCollatorAPI miner.CollatorAPI

if config.Miner.UseCustomCollator {
log.Info("using custom mining collator")
var err error
minerCollator, minerCollatorAPI, err = miner.LoadCollator(config.Miner.CollatorPath, config.Miner.CollatorConfigPath)
if err != nil {
return nil, err
}
}

if config.NoPruning && config.TrieDirtyCache > 0 {
if config.SnapshotCache > 0 {
config.TrieCleanCache += config.TrieDirtyCache * 3 / 5
Expand Down Expand Up @@ -225,7 +238,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock, minerCollator, minerCollatorAPI)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))

eth.APIBackend = &EthAPIBackend{stack.Config().ExtRPCEnabled(), stack.Config().AllowUnprotectedTxs, eth, nil}
Expand Down Expand Up @@ -297,6 +310,15 @@ func (s *Ethereum) APIs() []rpc.API {
// Append any APIs exposed explicitly by the consensus engine
apis = append(apis, s.engine.APIs(s.BlockChain())...)

if s.config.Miner.UseCustomCollator && s.miner.API != nil {
apis = append(apis, rpc.API{
Namespace: "minercollator",
Version: s.miner.API.Version(),
Service: s.miner.API.Service(),
Public: true,
})
}

// Append all the local APIs and return
return append(apis, []rpc.API{
{
Expand Down
11 changes: 7 additions & 4 deletions eth/ethconfig/config.go
Expand Up @@ -83,10 +83,13 @@ var Defaults = Config{
TrieTimeout: 60 * time.Minute,
SnapshotCache: 102,
Miner: miner.Config{
GasFloor: 8000000,
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
GasFloor: 8000000,
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
UseCustomCollator: false,
CollatorPath: "",
CollatorConfigPath: "",
},
TxPool: core.DefaultTxPoolConfig,
RPCGasCap: 50000000,
Expand Down