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

Commit

Permalink
Merge branch 'master' into nope
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuba authored May 17, 2020
2 parents 2e552f3 + a6f37e2 commit bdb9411
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func Start(c *cli.Context) error {
ctx,
config.LibP2P,
networkPrivateKey,
libp2p.ProtocolECDSA,
firewall.NewStakeOrActiveKeepPolicy(ethereumChain, stakeMonitor),
retransmission.NewTimeTicker(ctx, 1*time.Second),
libp2p.WithRoutingTableRefreshPeriod(routingTableRefreshPeriod),
Expand Down
15 changes: 15 additions & 0 deletions configs/config.toml.SAMPLE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@
[ethereum]
URL = "ws://127.0.0.1:8545"
URLRPC = "http://127.0.0.1:8546"
# Uncomment to override the defaults for transaction status monitoring.
#
# MiningCheckInterval is the interval in which transaction
# mining status is checked. If the transaction is not mined within this
# time, the gas price is increased and transaction is resubmitted.
#
# MiningCheckInterval = 60 # 60 sec (default value)
#
# MaxGasPrice specifies the default maximum gas price the client is
# willing to pay for the transaction to be mined. The offered transaction
# gas price can not be higher than the max gas price value. If the maximum
# allowed gas price is reached, no further resubmission attempts are
# performed.
#
# MaxGasPrice = 50000000000 # 50 gwei (default value)

[ethereum.account]
KeyFile = "/Users/someuser/ethereum/data/keystore/UTC--2018-03-11T01-37-33.202765887Z--AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAA"
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ require (
github.com/gogo/protobuf v1.3.1
github.com/google/gofuzz v1.1.0
github.com/ipfs/go-log v0.0.1
github.com/keep-network/keep-common v1.0.0
github.com/keep-network/keep-core v1.1.3
github.com/keep-network/keep-common v1.0.1-0.20200515214626-9036c7c35946
github.com/keep-network/keep-core v0.14.1-rc.0.20200516202120-19889483db36
github.com/pkg/errors v0.9.1
github.com/urfave/cli v1.22.1
)
10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,10 @@ github.com/keep-network/cli v1.20.0 h1:mEufpPsovOVdduTTkk+a2CxS3crIrGFqUsvs58gSi
github.com/keep-network/cli v1.20.0/go.mod h1:nzsst4JjU+rGE8Q5J839fYxectxWHpLhxKNohQWtQhA=
github.com/keep-network/go-libp2p-bootstrap v0.0.0-20200423153828-ed815bc50aec h1:2pXAsi4OUUjZKr5ds5UOF2IxXN+jVW0WetVO+czkf+A=
github.com/keep-network/go-libp2p-bootstrap v0.0.0-20200423153828-ed815bc50aec/go.mod h1:xR8jf3/VJAjh3nWu5tFe8Yxnt2HvWsqZHfGef1P5oDk=
github.com/keep-network/keep-common v0.3.2 h1:Yty+rgBXLD2yfWvqG4r45SIHUbyTfuQeFtZDonz9kBs=
github.com/keep-network/keep-common v0.3.2/go.mod h1:0uY+hufkP66nFnL+3GXMwWXRiKKsFyXFQTby1xR7AwY=
github.com/keep-network/keep-common v1.0.0 h1:buLpkvahX5oJc6DIQZe7aAxTJqyWx61xM1uSUD8UVCY=
github.com/keep-network/keep-common v1.0.0/go.mod h1:0uY+hufkP66nFnL+3GXMwWXRiKKsFyXFQTby1xR7AwY=
github.com/keep-network/keep-core v1.1.3 h1:YWJfs6dCImWlGYV8JP9lHunDDfk48ngp0e8fCEWKF68=
github.com/keep-network/keep-core v1.1.3/go.mod h1:xhPlO1jYmapYwR9uKWWAubDdfaZ5NMru7XqxWRyrmq4=
github.com/keep-network/keep-common v1.0.1-0.20200515214626-9036c7c35946 h1:fvkIlIuuEd42K2U4E2cYFlTpBt0F6JysDg6zBkxXRPM=
github.com/keep-network/keep-common v1.0.1-0.20200515214626-9036c7c35946/go.mod h1:0uY+hufkP66nFnL+3GXMwWXRiKKsFyXFQTby1xR7AwY=
github.com/keep-network/keep-core v0.14.1-rc.0.20200516202120-19889483db36 h1:cAlN9bA+6/qiYxGawvu8PzQBut+MRF8RevkmTO+selg=
github.com/keep-network/keep-core v0.14.1-rc.0.20200516202120-19889483db36/go.mod h1:nDEcqn7EBbTsn0RhGFqJMRKU0X7mYdrlE/XPUGM1YI4=
github.com/keep-network/toml v0.3.0 h1:G+NJwWR/ZiORqeLBsDXDchYoL29PXHdxOPcCueA7ctE=
github.com/keep-network/toml v0.3.0/go.mod h1:Zeyd3lxbIlMYLREho3UK1dMP2xjqt2gLkQ5E5vM6K38=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down
33 changes: 33 additions & 0 deletions pkg/chain/ethereum/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package ethereum

import (
"fmt"
"math/big"
"sync"
"time"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/ethclient"
Expand All @@ -14,13 +16,29 @@ import (
"github.com/keep-network/keep-ecdsa/pkg/chain/gen/contract"
)

var (
// DefaultMiningCheckInterval is the default interval in which transaction
// mining status is checked. If the transaction is not mined within this
// time, the gas price is increased and transaction is resubmitted.
// This value can be overwritten in the configuration file.
DefaultMiningCheckInterval = 60 * time.Second

// DefaultMaxGasPrice specifies the default maximum gas price the client is
// willing to pay for the transaction to be mined. The offered transaction
// gas price can not be higher than the max gas price value. If the maximum
// allowed gas price is reached, no further resubmission attempts are
// performed. This value can be overwritten in the configuration file.
DefaultMaxGasPrice = big.NewInt(50000000000) // 50 Gwei
)

// EthereumChain is an implementation of ethereum blockchain interface.
type EthereumChain struct {
config *ethereum.Config
accountKey *keystore.Key
client *ethclient.Client
bondedECDSAKeepFactoryContract *contract.BondedECDSAKeepFactory
blockCounter *blockcounter.EthereumBlockCounter
miningWaiter *ethutil.MiningWaiter
nonceManager *ethutil.NonceManager

// transactionMutex allows interested parties to forcibly serialize
Expand Down Expand Up @@ -53,6 +71,19 @@ func Connect(accountKey *keystore.Key, config *ethereum.Config) (eth.Handle, err
client,
)

checkInterval := DefaultMiningCheckInterval
maxGasPrice := DefaultMaxGasPrice
if config.MiningCheckInterval != 0 {
checkInterval = time.Duration(config.MiningCheckInterval) * time.Second
}
if config.MaxGasPrice != 0 {
maxGasPrice = new(big.Int).SetUint64(config.MaxGasPrice)
}

logger.Infof("using [%v] mining check interval", checkInterval)
logger.Infof("using [%v] wei max gas price", maxGasPrice)
miningWaiter := ethutil.NewMiningWaiter(client, checkInterval, maxGasPrice)

bondedECDSAKeepFactoryContractAddress, err := config.ContractAddress(BondedECDSAKeepFactoryContractName)
if err != nil {
return nil, err
Expand All @@ -62,6 +93,7 @@ func Connect(accountKey *keystore.Key, config *ethereum.Config) (eth.Handle, err
accountKey,
client,
nonceManager,
miningWaiter,
transactionMutex,
)
if err != nil {
Expand All @@ -83,6 +115,7 @@ func Connect(accountKey *keystore.Key, config *ethereum.Config) (eth.Handle, err
bondedECDSAKeepFactoryContract: bondedECDSAKeepFactoryContract,
blockCounter: blockCounter,
nonceManager: nonceManager,
miningWaiter: miningWaiter,
transactionMutex: transactionMutex,
}, nil
}
1 change: 1 addition & 0 deletions pkg/chain/ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ func (ec *EthereumChain) getKeepContract(address common.Address) (*contract.Bond
ec.accountKey,
ec.client,
ec.nonceManager,
ec.miningWaiter,
ec.transactionMutex,
)
if err != nil {
Expand Down

0 comments on commit bdb9411

Please sign in to comment.