Skip to content

Commit

Permalink
les: fix setOracle for chains without checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
fjl committed Jul 10, 2020
1 parent 93f4b7a commit 30bd6c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
10 changes: 0 additions & 10 deletions les/checkpointoracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ type CheckpointOracle struct {

// New creates a checkpoint oracle handler with given configs and callback.
func New(config *params.CheckpointOracleConfig, getLocal func(uint64) params.TrustedCheckpoint) *CheckpointOracle {
if config == nil {
log.Info("Checkpoint registrar is not enabled")
return nil
}
if config.Address == (common.Address{}) || uint64(len(config.Signers)) < config.Threshold {
log.Warn("Invalid checkpoint registrar config")
return nil
}
log.Info("Configured checkpoint registrar", "address", config.Address, "signers", len(config.Signers), "threshold", config.Threshold)

return &CheckpointOracle{
config: config,
getLocal: getLocal,
Expand Down
21 changes: 16 additions & 5 deletions les/commons.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/checkpointoracle"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discv5"
Expand Down Expand Up @@ -149,14 +150,24 @@ func (c *lesCommons) localCheckpoint(index uint64) params.TrustedCheckpoint {
}

// setupOracle sets up the checkpoint oracle contract client.
func (c *lesCommons) setupOracle(node *node.Node, genesis common.Hash, config *eth.Config) *checkpointoracle.CheckpointOracle {
cfg := config.CheckpointOracle
if cfg == nil {
cfg = params.CheckpointOracles[genesis]
func (c *lesCommons) setupOracle(node *node.Node, genesis common.Hash, ethconfig *eth.Config) *checkpointoracle.CheckpointOracle {
config := ethconfig.CheckpointOracle
if config == nil {
// Try loading default config.
config = params.CheckpointOracles[genesis]
}
oracle := checkpointoracle.New(cfg, c.localCheckpoint)
if config == nil {
log.Info("Checkpoint registrar is not enabled")
return nil
}
if config.Address == (common.Address{}) || uint64(len(config.Signers)) < config.Threshold {
log.Warn("Invalid checkpoint registrar config")
return nil
}
oracle := checkpointoracle.New(config, c.localCheckpoint)
rpcClient, _ := node.Attach()
client := ethclient.NewClient(rpcClient)
oracle.Start(client)
log.Info("Configured checkpoint registrar", "address", config.Address, "signers", len(config.Signers), "threshold", config.Threshold)
return oracle
}

0 comments on commit 30bd6c7

Please sign in to comment.