Skip to content

Commit

Permalink
Enable miners to select the verification service they want to use (et…
Browse files Browse the repository at this point in the history
…hereum#55)

* Add a flag for the url to which we send verification requests

* Added some missing default settings for VerificationRewardsAddressFlag

* Cleaning up a few files with -s caught by the linter

* Removing changes related to rewards for a later PR, changing variable names for clarity over conciseness, and fixing typos

* Missed some files on the last commit

* removed old comments and debug stuff form abe.go

* Fix linting errors

* Changing placement of VerificationServiceURLFlag to go with the rest of the miner flags. renaming its tag to have the "miner." prefix

* adding miner tag to flag and other places, removing link to prod verification service in geth test, and

* responding to minor comments on PR

* gofmting files
  • Loading branch information
savajudah authored Oct 12, 2018
1 parent bbd1057 commit b089c7c
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
10 changes: 4 additions & 6 deletions abe/abe.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ func createVerificationMessage(request types.VerificationRequest, verificationRe
return fmt.Sprintf("Celo verification code: %s:%d:%s", base64.URLEncoding.EncodeToString(signature), request.VerificationIndex, base64.URLEncoding.EncodeToString(verificationRewardsAddress.Bytes())), nil
}

func sendSms(phoneNumber string, message string) error {
func sendSms(phoneNumber string, message string, verificationServiceURL string) error {
// Send the actual text message using our mining pool.
// TODO: Make mining pool be configurable via command line arguments.
url := "https://mining-pool.celo.org/v0.1/sms"
values := map[string]string{"phoneNumber": phoneNumber, "message": message}
jsonValue, _ := json.Marshal(values)
var err error

// Retry 5 times if we fail.
for i := 0; i < 5; i++ {
_, err := http.Post(url, "application/json", bytes.NewBuffer(jsonValue))
_, err := http.Post(verificationServiceURL, "application/json", bytes.NewBuffer(jsonValue))
if err == nil {
break
}
Expand All @@ -76,7 +74,7 @@ func sendSms(phoneNumber string, message string) error {
return err
}

func SendVerificationMessages(receipts []*types.Receipt, block *types.Block, coinbase common.Address, accountManager *accounts.Manager, verificationRewardsAddress common.Address) {
func SendVerificationMessages(receipts []*types.Receipt, block *types.Block, coinbase common.Address, accountManager *accounts.Manager, verificationServiceURL string, verificationRewardsAddress common.Address) {
account := accounts.Account{Address: coinbase}
wallet, err := accountManager.Find(account)
if err != nil {
Expand All @@ -103,7 +101,7 @@ func SendVerificationMessages(receipts []*types.Receipt, block *types.Block, coi
}

log.Debug(fmt.Sprintf("[Celo] Sending verification message: \"%s\"", message), nil, nil)
err = sendSms(phoneNumber, message)
err = sendSms(phoneNumber, message, verificationServiceURL)
if err != nil {
log.Error("[Celo] Failed to send SMS", "err", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/node"
"gopkg.in/urfave/cli.v1"
cli "gopkg.in/urfave/cli.v1"
)

const (
Expand Down Expand Up @@ -110,6 +110,7 @@ var (
utils.MinerLegacyExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.MinerVerificationServiceUrlFlag,
utils.MinerVerificationRewardsFlag,
utils.NATFlag,
utils.NoDiscoverFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.MinerExtraDataFlag,
utils.MinerRecommitIntervalFlag,
utils.MinerNoVerfiyFlag,
utils.MinerVerificationServiceUrlFlag,
utils.MinerVerificationRewardsFlag,
},
},
Expand Down
10 changes: 9 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,17 @@ var (
Name: "miner.noverify",
Usage: "Disable remote sealing verification",
}
MinerVerificationServiceUrlFlag = cli.StringFlag{
Name: "miner.verificationpool",
Usage: "URL to the verification service to be used by the miner to verify users' phone numbers",
Value: eth.DefaultConfig.MinerVerificationServiceUrl,
}
MinerVerificationRewardsFlag = cli.StringFlag{
Name: "miner.verificationrewards",
Usage: "Account address to which to send the verification rewards.",
// TODO(sklanje): Update this to Celo verification pool address.
Value: "0xfeE1a22F43BeeCB912B5a4912ba87527682ef0fC",
}

// Account settings
UnlockedAccountFlag = cli.StringFlag{
Name: "unlock",
Expand Down Expand Up @@ -1203,6 +1207,10 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
}

if ctx.GlobalIsSet(MinerVerificationServiceUrlFlag.Name) {
cfg.MinerVerificationServiceUrl = ctx.GlobalString(MinerVerificationServiceUrlFlag.Name)
}

// Override any default configs for hard coded networks.
switch {
case ctx.GlobalBool(TestnetFlag.Name):
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, config.MinerVerificationRewards)
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, config.MinerVerificationServiceUrl, config.MinerVerificationRewards)
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))

eth.APIBackend = &EthAPIBackend{eth, nil}
Expand Down
38 changes: 20 additions & 18 deletions eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ var DefaultConfig = Config{
DatasetsInMem: 1,
DatasetsOnDisk: 2,
},
NetworkId: 1,
LightPeers: 100,
DatabaseCache: 768,
TrieCache: 256,
TrieTimeout: 60 * time.Minute,
MinerGasFloor: 8000000,
MinerGasCeil: 8000000,
MinerGasPrice: big.NewInt(params.GWei),
MinerRecommit: 3 * time.Second,
NetworkId: 1,
LightPeers: 100,
DatabaseCache: 768,
TrieCache: 256,
TrieTimeout: 60 * time.Minute,
MinerGasFloor: 8000000,
MinerGasCeil: 8000000,
MinerGasPrice: big.NewInt(params.GWei),
MinerRecommit: 3 * time.Second,
MinerVerificationServiceUrl: "https://mining-pool.celo.org/v0.1/sms",

TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
Expand Down Expand Up @@ -98,15 +99,16 @@ type Config struct {
TrieTimeout time.Duration

// Mining-related options
Etherbase common.Address `toml:",omitempty"`
MinerNotify []string `toml:",omitempty"`
MinerExtraData []byte `toml:",omitempty"`
MinerGasFloor uint64
MinerGasCeil uint64
MinerGasPrice *big.Int
MinerRecommit time.Duration
MinerNoverify bool
MinerVerificationRewards common.Address
Etherbase common.Address `toml:",omitempty"`
MinerNotify []string `toml:",omitempty"`
MinerExtraData []byte `toml:",omitempty"`
MinerGasFloor uint64
MinerGasCeil uint64
MinerGasPrice *big.Int
MinerRecommit time.Duration
MinerNoverify bool
MinerVerificationServiceUrl string
MinerVerificationRewards common.Address

// Ethash options
Ethash ethash.Config
Expand Down
4 changes: 2 additions & 2 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ type Miner struct {
shouldStart int32 // should start indicates whether we should start after sync
}

func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64, verificationRewards common.Address) *Miner {
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64, verificationService string, verificationRewards common.Address) *Miner {
miner := &Miner{
eth: eth,
mux: mux,
engine: engine,
exitCh: make(chan struct{}),
worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil, verificationRewards),
worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil, verificationService, verificationRewards),
canStart: 1,
}
go miner.update()
Expand Down
6 changes: 4 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ type worker struct {
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.

// Verification Service
verificationService string
verificationRewards common.Address
}

func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, verificationRewards common.Address) *worker {
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, verificationService string, verificationRewards common.Address) *worker {
worker := &worker{
config: config,
engine: engine,
Expand All @@ -189,6 +190,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
chain: eth.BlockChain(),
gasFloor: gasFloor,
gasCeil: gasCeil,
verificationService: verificationService,
verificationRewards: verificationRewards,
possibleUncles: make(map[common.Hash]*types.Block),
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
Expand Down Expand Up @@ -966,7 +968,7 @@ func (w *worker) commit(uncles []*types.Header, interval func(), update bool, st

log.Info("Commit new mining work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
"uncles", len(uncles), "txs", w.current.tcount, "gas", block.GasUsed(), "fees", feesEth, "elapsed", common.PrettyDuration(time.Since(start)))
abe.SendVerificationMessages(w.current.receipts, block, w.coinbase, w.eth.AccountManager(), w.verificationRewards)
abe.SendVerificationMessages(w.current.receipts, block, w.coinbase, w.eth.AccountManager(), w.verificationService, w.verificationRewards)

case <-w.exitCh:
log.Info("Worker has exited")
Expand Down
3 changes: 2 additions & 1 deletion miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
testUserKey, _ = crypto.GenerateKey()
testUserAddress = crypto.PubkeyToAddress(testUserKey.PublicKey)

testVerificationService = ""
testVerificationRewardsKey, _ = crypto.GenerateKey()
testVerificationRewardsAddress = crypto.PubkeyToAddress(testVerificationRewardsKey.PublicKey)

Expand Down Expand Up @@ -143,7 +144,7 @@ func (b *testWorkerBackend) PostChainEvents(events []interface{}) {
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, blocks int) (*worker, *testWorkerBackend) {
backend := newTestWorkerBackend(t, chainConfig, engine, blocks)
backend.txPool.AddLocals(pendingTxs)
w := newWorker(chainConfig, engine, backend, new(event.TypeMux), time.Second, params.GenesisGasLimit, params.GenesisGasLimit, testVerificationRewardsAddress)
w := newWorker(chainConfig, engine, backend, new(event.TypeMux), time.Second, params.GenesisGasLimit, params.GenesisGasLimit, testVerificationService, testVerificationRewardsAddress)
w.setEtherbase(testBankAddress)
return w, backend
}
Expand Down

0 comments on commit b089c7c

Please sign in to comment.