mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
Merge pull request #559 from gzliudan/eip1559-1
some PR before EIP-1559
This commit is contained in:
commit
73308897d4
35 changed files with 428 additions and 198 deletions
|
|
@ -20,16 +20,29 @@ import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||||
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
|
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNoChainID is returned whenever the user failed to specify a chain id.
|
||||||
|
var ErrNoChainID = errors.New("no chain id specified")
|
||||||
|
|
||||||
|
// ErrNotAuthorized is returned when an account is not properly unlocked.
|
||||||
|
var ErrNotAuthorized = errors.New("not authorized to sign this account")
|
||||||
|
|
||||||
// NewTransactor is a utility method to easily create a transaction signer from
|
// NewTransactor is a utility method to easily create a transaction signer from
|
||||||
// an encrypted json key stream and the associated passphrase.
|
// an encrypted json key stream and the associated passphrase.
|
||||||
|
//
|
||||||
|
// Deprecated: Use NewTransactorWithChainID instead.
|
||||||
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
|
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
|
||||||
|
log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID")
|
||||||
json, err := io.ReadAll(keyin)
|
json, err := io.ReadAll(keyin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -43,13 +56,17 @@ func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
|
||||||
|
|
||||||
// NewKeyedTransactor is a utility method to easily create a transaction signer
|
// NewKeyedTransactor is a utility method to easily create a transaction signer
|
||||||
// from a single private key.
|
// from a single private key.
|
||||||
|
//
|
||||||
|
// Deprecated: Use NewKeyedTransactorWithChainID instead.
|
||||||
func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
|
func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
|
||||||
|
log.Warn("WARNING: NewKeyedTransactor has been deprecated in favour of NewKeyedTransactorWithChainID")
|
||||||
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
|
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
signer := types.HomesteadSigner{}
|
||||||
return &TransactOpts{
|
return &TransactOpts{
|
||||||
From: keyAddr,
|
From: keyAddr,
|
||||||
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||||
if address != keyAddr {
|
if address != keyAddr {
|
||||||
return nil, errors.New("not authorized to sign this account")
|
return nil, ErrNotAuthorized
|
||||||
}
|
}
|
||||||
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
|
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -59,3 +76,62 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTransactorWithChainID is a utility method to easily create a transaction signer from
|
||||||
|
// an encrypted json key stream and the associated passphrase.
|
||||||
|
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
|
||||||
|
json, err := ioutil.ReadAll(keyin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
key, err := keystore.DecryptKey(json, passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return NewKeyedTransactorWithChainID(key.PrivateKey, chainID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewKeyStoreTransactorWithChainID is a utility method to easily create a transaction signer from
|
||||||
|
// an decrypted key from a keystore.
|
||||||
|
func NewKeyStoreTransactorWithChainID(keystore *keystore.KeyStore, account accounts.Account, chainID *big.Int) (*TransactOpts, error) {
|
||||||
|
if chainID == nil {
|
||||||
|
return nil, ErrNoChainID
|
||||||
|
}
|
||||||
|
signer := types.NewEIP155Signer(chainID)
|
||||||
|
return &TransactOpts{
|
||||||
|
From: account.Address,
|
||||||
|
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||||
|
if address != account.Address {
|
||||||
|
return nil, ErrNotAuthorized
|
||||||
|
}
|
||||||
|
signature, err := keystore.SignHash(account, signer.Hash(tx).Bytes())
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return tx.WithSignature(signer, signature)
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer
|
||||||
|
// from a single private key.
|
||||||
|
func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*TransactOpts, error) {
|
||||||
|
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
|
||||||
|
if chainID == nil {
|
||||||
|
return nil, ErrNoChainID
|
||||||
|
}
|
||||||
|
signer := types.NewEIP155Signer(chainID)
|
||||||
|
return &TransactOpts{
|
||||||
|
From: keyAddr,
|
||||||
|
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||||
|
if address != keyAddr {
|
||||||
|
return nil, ErrNotAuthorized
|
||||||
|
}
|
||||||
|
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return tx.WithSignature(signer, signature)
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,7 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi
|
||||||
|
|
||||||
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
|
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
|
||||||
// for testing purposes.
|
// for testing purposes.
|
||||||
|
// A simulated backend always uses chainID 1337.
|
||||||
func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend {
|
func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend {
|
||||||
database := rawdb.NewMemoryDatabase()
|
database := rawdb.NewMemoryDatabase()
|
||||||
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, Alloc: alloc, GasLimit: 42000000}
|
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, Alloc: alloc, GasLimit: 42000000}
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ var (
|
||||||
|
|
||||||
// SignerFn is a signer function callback when a contract requires a method to
|
// SignerFn is a signer function callback when a contract requires a method to
|
||||||
// sign the transaction before submission.
|
// sign the transaction before submission.
|
||||||
type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error)
|
type SignerFn func(common.Address, *types.Transaction) (*types.Transaction, error)
|
||||||
|
|
||||||
// CallOpts is the collection of options to fine tune a contract call request.
|
// CallOpts is the collection of options to fine tune a contract call request.
|
||||||
type CallOpts struct {
|
type CallOpts struct {
|
||||||
|
|
@ -238,7 +238,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
|
||||||
if opts.Signer == nil {
|
if opts.Signer == nil {
|
||||||
return nil, errors.New("no signer to authorize the transaction with")
|
return nil, errors.New("no signer to authorize the transaction with")
|
||||||
}
|
}
|
||||||
signedTx, err := opts.Signer(types.HomesteadSigner{}, opts.From, rawTx)
|
signedTx, err := opts.Signer(opts.From, rawTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy an interaction tester contract and call a transaction on it
|
// Deploy an interaction tester contract and call a transaction on it
|
||||||
|
|
@ -269,7 +269,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a tuple tester contract and execute a structured call on it
|
// Deploy a tuple tester contract and execute a structured call on it
|
||||||
|
|
@ -301,7 +301,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a tuple tester contract and execute a structured call on it
|
// Deploy a tuple tester contract and execute a structured call on it
|
||||||
|
|
@ -343,7 +343,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a slice tester contract and execute a n array call on it
|
// Deploy a slice tester contract and execute a n array call on it
|
||||||
|
|
@ -377,7 +377,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a default method invoker contract and execute its default method
|
// Deploy a default method invoker contract and execute its default method
|
||||||
|
|
@ -446,7 +446,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a funky gas pattern contract
|
// Deploy a funky gas pattern contract
|
||||||
|
|
@ -481,7 +481,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a sender tester contract and execute a structured call on it
|
// Deploy a sender tester contract and execute a structured call on it
|
||||||
|
|
@ -541,7 +541,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy a underscorer tester contract and execute a structured call on it
|
// Deploy a underscorer tester contract and execute a structured call on it
|
||||||
|
|
@ -611,7 +611,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
// Deploy an eventer contract
|
// Deploy an eventer contract
|
||||||
|
|
@ -760,7 +760,7 @@ var bindTests = []struct {
|
||||||
`
|
`
|
||||||
// Generate a new random account and a funded simulator
|
// Generate a new random account and a funded simulator
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
auth := bind.NewKeyedTransactor(key)
|
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
|
||||||
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
|
||||||
|
|
||||||
//deploy the test contract
|
//deploy the test contract
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/XDCx"
|
"github.com/XinFinOrg/XDPoSChain/XDCx"
|
||||||
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/debug"
|
"github.com/XinFinOrg/XDPoSChain/internal/debug"
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
|
|
@ -90,7 +90,7 @@ type Bootnodes struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type XDCConfig struct {
|
type XDCConfig struct {
|
||||||
Eth eth.Config
|
Eth ethconfig.Config
|
||||||
Shh whisper.Config
|
Shh whisper.Config
|
||||||
Node node.Config
|
Node node.Config
|
||||||
Ethstats ethstatsConfig
|
Ethstats ethstatsConfig
|
||||||
|
|
@ -129,7 +129,7 @@ func defaultNodeConfig() node.Config {
|
||||||
func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
|
func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
|
||||||
// Load defaults.
|
// Load defaults.
|
||||||
cfg := XDCConfig{
|
cfg := XDCConfig{
|
||||||
Eth: eth.DefaultConfig,
|
Eth: ethconfig.Defaults,
|
||||||
Shh: whisper.DefaultConfig,
|
Shh: whisper.DefaultConfig,
|
||||||
XDCX: XDCx.DefaultConfig,
|
XDCX: XDCx.DefaultConfig,
|
||||||
Node: defaultNodeConfig(),
|
Node: defaultNodeConfig(),
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,8 @@ var (
|
||||||
//utils.NoCompactionFlag,
|
//utils.NoCompactionFlag,
|
||||||
//utils.GpoBlocksFlag,
|
//utils.GpoBlocksFlag,
|
||||||
//utils.GpoPercentileFlag,
|
//utils.GpoPercentileFlag,
|
||||||
|
utils.GpoMaxGasPriceFlag,
|
||||||
|
utils.GpoIgnoreGasPriceFlag,
|
||||||
//utils.ExtraDataFlag,
|
//utils.ExtraDataFlag,
|
||||||
configFileFlag,
|
configFileFlag,
|
||||||
utils.AnnounceTxsFlag,
|
utils.AnnounceTxsFlag,
|
||||||
|
|
@ -148,6 +150,7 @@ var (
|
||||||
utils.WSAllowedOriginsFlag,
|
utils.WSAllowedOriginsFlag,
|
||||||
utils.IPCDisabledFlag,
|
utils.IPCDisabledFlag,
|
||||||
utils.IPCPathFlag,
|
utils.IPCPathFlag,
|
||||||
|
utils.RPCGlobalTxFeeCap,
|
||||||
}
|
}
|
||||||
|
|
||||||
whisperFlags = []cli.Flag{
|
whisperFlags = []cli.Flag{
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
"gopkg.in/urfave/cli.v1"
|
"gopkg.in/urfave/cli.v1"
|
||||||
)
|
)
|
||||||
|
|
@ -114,7 +115,7 @@ func version(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
fmt.Println("Architecture:", runtime.GOARCH)
|
fmt.Println("Architecture:", runtime.GOARCH)
|
||||||
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
||||||
fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
|
fmt.Println("Network Id:", ethconfig.Defaults.NetworkId)
|
||||||
fmt.Println("Go Version:", runtime.Version())
|
fmt.Println("Go Version:", runtime.Version())
|
||||||
fmt.Println("Operating System:", runtime.GOOS)
|
fmt.Println("Operating System:", runtime.GOOS)
|
||||||
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ var AppHelpFlagGroups = []flagGroup{
|
||||||
utils.IPCPathFlag,
|
utils.IPCPathFlag,
|
||||||
utils.RPCCORSDomainFlag,
|
utils.RPCCORSDomainFlag,
|
||||||
utils.RPCVirtualHostsFlag,
|
utils.RPCVirtualHostsFlag,
|
||||||
|
utils.RPCGlobalTxFeeCap,
|
||||||
utils.JSpathFlag,
|
utils.JSpathFlag,
|
||||||
utils.ExecFlag,
|
utils.ExecFlag,
|
||||||
utils.PreloadJSFlag,
|
utils.PreloadJSFlag,
|
||||||
|
|
@ -194,6 +195,8 @@ var AppHelpFlagGroups = []flagGroup{
|
||||||
// Flags: []cli.Flag{
|
// Flags: []cli.Flag{
|
||||||
// utils.GpoBlocksFlag,
|
// utils.GpoBlocksFlag,
|
||||||
// utils.GpoPercentileFlag,
|
// utils.GpoPercentileFlag,
|
||||||
|
// utils.GpoMaxGasPriceFlag,
|
||||||
|
// utils.GpoIgnoreGasPriceFlag,
|
||||||
// },
|
// },
|
||||||
//},
|
//},
|
||||||
//{
|
//{
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethclient"
|
"github.com/XinFinOrg/XDPoSChain/ethclient"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
||||||
"github.com/XinFinOrg/XDPoSChain/les"
|
"github.com/XinFinOrg/XDPoSChain/les"
|
||||||
|
|
@ -239,7 +239,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u
|
||||||
}
|
}
|
||||||
// Assemble the Ethereum light client protocol
|
// Assemble the Ethereum light client protocol
|
||||||
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
cfg := eth.DefaultConfig
|
cfg := ethconfig.Defaults
|
||||||
cfg.SyncMode = downloader.LightSync
|
cfg.SyncMode = downloader.LightSync
|
||||||
cfg.NetworkId = network
|
cfg.NetworkId = network
|
||||||
cfg.Genesis = genesis
|
cfg.Genesis = genesis
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb/leveldb"
|
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
@ -16,11 +13,14 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/ethdb/leveldb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rlp"
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
||||||
"github.com/XinFinOrg/XDPoSChain/trie"
|
"github.com/XinFinOrg/XDPoSChain/trie"
|
||||||
"github.com/hashicorp/golang-lru"
|
lru "github.com/hashicorp/golang-lru"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -52,7 +52,7 @@ type ResultProcessNode struct {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
db, _ := leveldb.New(*dir, eth.DefaultConfig.DatabaseCache, utils.MakeDatabaseHandles(), "")
|
db, _ := leveldb.New(*dir, ethconfig.Defaults.DatabaseCache, utils.MakeDatabaseHandles(), "")
|
||||||
lddb := rawdb.NewDatabase(db)
|
lddb := rawdb.NewDatabase(db)
|
||||||
head := core.GetHeadBlockHash(lddb)
|
head := core.GetHeadBlockHash(lddb)
|
||||||
currentHeader := core.GetHeader(lddb, head, core.GetBlockNumber(lddb, head))
|
currentHeader := core.GetHeader(lddb, head, core.GetBlockNumber(lddb, head))
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
|
|
@ -148,7 +148,7 @@ var (
|
||||||
NetworkIdFlag = cli.Uint64Flag{
|
NetworkIdFlag = cli.Uint64Flag{
|
||||||
Name: "networkid",
|
Name: "networkid",
|
||||||
Usage: "Network identifier (integer, 89=XDPoSChain)",
|
Usage: "Network identifier (integer, 89=XDPoSChain)",
|
||||||
Value: eth.DefaultConfig.NetworkId,
|
Value: ethconfig.Defaults.NetworkId,
|
||||||
}
|
}
|
||||||
TestnetFlag = cli.BoolFlag{
|
TestnetFlag = cli.BoolFlag{
|
||||||
Name: "testnet",
|
Name: "testnet",
|
||||||
|
|
@ -187,7 +187,7 @@ var (
|
||||||
Name: "light",
|
Name: "light",
|
||||||
Usage: "Enable light client mode",
|
Usage: "Enable light client mode",
|
||||||
}
|
}
|
||||||
defaultSyncMode = eth.DefaultConfig.SyncMode
|
defaultSyncMode = ethconfig.Defaults.SyncMode
|
||||||
SyncModeFlag = TextMarshalerFlag{
|
SyncModeFlag = TextMarshalerFlag{
|
||||||
Name: "syncmode",
|
Name: "syncmode",
|
||||||
Usage: `Blockchain sync mode ("fast", "full", or "light")`,
|
Usage: `Blockchain sync mode ("fast", "full", or "light")`,
|
||||||
|
|
@ -206,7 +206,7 @@ var (
|
||||||
LightPeersFlag = cli.IntFlag{
|
LightPeersFlag = cli.IntFlag{
|
||||||
Name: "lightpeers",
|
Name: "lightpeers",
|
||||||
Usage: "Maximum number of LES client peers",
|
Usage: "Maximum number of LES client peers",
|
||||||
Value: eth.DefaultConfig.LightPeers,
|
Value: ethconfig.Defaults.LightPeers,
|
||||||
}
|
}
|
||||||
LightKDFFlag = cli.BoolFlag{
|
LightKDFFlag = cli.BoolFlag{
|
||||||
Name: "lightkdf",
|
Name: "lightkdf",
|
||||||
|
|
@ -225,27 +225,27 @@ var (
|
||||||
EthashCachesInMemoryFlag = cli.IntFlag{
|
EthashCachesInMemoryFlag = cli.IntFlag{
|
||||||
Name: "ethash.cachesinmem",
|
Name: "ethash.cachesinmem",
|
||||||
Usage: "Number of recent ethash caches to keep in memory (16MB each)",
|
Usage: "Number of recent ethash caches to keep in memory (16MB each)",
|
||||||
Value: eth.DefaultConfig.Ethash.CachesInMem,
|
Value: ethconfig.Defaults.Ethash.CachesInMem,
|
||||||
}
|
}
|
||||||
EthashCachesOnDiskFlag = cli.IntFlag{
|
EthashCachesOnDiskFlag = cli.IntFlag{
|
||||||
Name: "ethash.cachesondisk",
|
Name: "ethash.cachesondisk",
|
||||||
Usage: "Number of recent ethash caches to keep on disk (16MB each)",
|
Usage: "Number of recent ethash caches to keep on disk (16MB each)",
|
||||||
Value: eth.DefaultConfig.Ethash.CachesOnDisk,
|
Value: ethconfig.Defaults.Ethash.CachesOnDisk,
|
||||||
}
|
}
|
||||||
EthashDatasetDirFlag = DirectoryFlag{
|
EthashDatasetDirFlag = DirectoryFlag{
|
||||||
Name: "ethash.dagdir",
|
Name: "ethash.dagdir",
|
||||||
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
|
Usage: "Directory to store the ethash mining DAGs (default = inside home folder)",
|
||||||
Value: DirectoryString{eth.DefaultConfig.Ethash.DatasetDir},
|
Value: DirectoryString{ethconfig.Defaults.Ethash.DatasetDir},
|
||||||
}
|
}
|
||||||
EthashDatasetsInMemoryFlag = cli.IntFlag{
|
EthashDatasetsInMemoryFlag = cli.IntFlag{
|
||||||
Name: "ethash.dagsinmem",
|
Name: "ethash.dagsinmem",
|
||||||
Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
|
Usage: "Number of recent ethash mining DAGs to keep in memory (1+GB each)",
|
||||||
Value: eth.DefaultConfig.Ethash.DatasetsInMem,
|
Value: ethconfig.Defaults.Ethash.DatasetsInMem,
|
||||||
}
|
}
|
||||||
EthashDatasetsOnDiskFlag = cli.IntFlag{
|
EthashDatasetsOnDiskFlag = cli.IntFlag{
|
||||||
Name: "ethash.dagsondisk",
|
Name: "ethash.dagsondisk",
|
||||||
Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
|
Usage: "Number of recent ethash mining DAGs to keep on disk (1+GB each)",
|
||||||
Value: eth.DefaultConfig.Ethash.DatasetsOnDisk,
|
Value: ethconfig.Defaults.Ethash.DatasetsOnDisk,
|
||||||
}
|
}
|
||||||
// Transaction pool settings
|
// Transaction pool settings
|
||||||
TxPoolNoLocalsFlag = cli.BoolFlag{
|
TxPoolNoLocalsFlag = cli.BoolFlag{
|
||||||
|
|
@ -265,37 +265,37 @@ var (
|
||||||
TxPoolPriceLimitFlag = cli.Uint64Flag{
|
TxPoolPriceLimitFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.pricelimit",
|
Name: "txpool.pricelimit",
|
||||||
Usage: "Minimum gas price limit to enforce for acceptance into the pool",
|
Usage: "Minimum gas price limit to enforce for acceptance into the pool",
|
||||||
Value: eth.DefaultConfig.TxPool.PriceLimit,
|
Value: ethconfig.Defaults.TxPool.PriceLimit,
|
||||||
}
|
}
|
||||||
TxPoolPriceBumpFlag = cli.Uint64Flag{
|
TxPoolPriceBumpFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.pricebump",
|
Name: "txpool.pricebump",
|
||||||
Usage: "Price bump percentage to replace an already existing transaction",
|
Usage: "Price bump percentage to replace an already existing transaction",
|
||||||
Value: eth.DefaultConfig.TxPool.PriceBump,
|
Value: ethconfig.Defaults.TxPool.PriceBump,
|
||||||
}
|
}
|
||||||
TxPoolAccountSlotsFlag = cli.Uint64Flag{
|
TxPoolAccountSlotsFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.accountslots",
|
Name: "txpool.accountslots",
|
||||||
Usage: "Minimum number of executable transaction slots guaranteed per account",
|
Usage: "Minimum number of executable transaction slots guaranteed per account",
|
||||||
Value: eth.DefaultConfig.TxPool.AccountSlots,
|
Value: ethconfig.Defaults.TxPool.AccountSlots,
|
||||||
}
|
}
|
||||||
TxPoolGlobalSlotsFlag = cli.Uint64Flag{
|
TxPoolGlobalSlotsFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.globalslots",
|
Name: "txpool.globalslots",
|
||||||
Usage: "Maximum number of executable transaction slots for all accounts",
|
Usage: "Maximum number of executable transaction slots for all accounts",
|
||||||
Value: eth.DefaultConfig.TxPool.GlobalSlots,
|
Value: ethconfig.Defaults.TxPool.GlobalSlots,
|
||||||
}
|
}
|
||||||
TxPoolAccountQueueFlag = cli.Uint64Flag{
|
TxPoolAccountQueueFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.accountqueue",
|
Name: "txpool.accountqueue",
|
||||||
Usage: "Maximum number of non-executable transaction slots permitted per account",
|
Usage: "Maximum number of non-executable transaction slots permitted per account",
|
||||||
Value: eth.DefaultConfig.TxPool.AccountQueue,
|
Value: ethconfig.Defaults.TxPool.AccountQueue,
|
||||||
}
|
}
|
||||||
TxPoolGlobalQueueFlag = cli.Uint64Flag{
|
TxPoolGlobalQueueFlag = cli.Uint64Flag{
|
||||||
Name: "txpool.globalqueue",
|
Name: "txpool.globalqueue",
|
||||||
Usage: "Maximum number of non-executable transaction slots for all accounts",
|
Usage: "Maximum number of non-executable transaction slots for all accounts",
|
||||||
Value: eth.DefaultConfig.TxPool.GlobalQueue,
|
Value: ethconfig.Defaults.TxPool.GlobalQueue,
|
||||||
}
|
}
|
||||||
TxPoolLifetimeFlag = cli.DurationFlag{
|
TxPoolLifetimeFlag = cli.DurationFlag{
|
||||||
Name: "txpool.lifetime",
|
Name: "txpool.lifetime",
|
||||||
Usage: "Maximum amount of time non-executable transaction are queued",
|
Usage: "Maximum amount of time non-executable transaction are queued",
|
||||||
Value: eth.DefaultConfig.TxPool.Lifetime,
|
Value: ethconfig.Defaults.TxPool.Lifetime,
|
||||||
}
|
}
|
||||||
// Performance tuning settings
|
// Performance tuning settings
|
||||||
CacheFlag = cli.IntFlag{
|
CacheFlag = cli.IntFlag{
|
||||||
|
|
@ -336,7 +336,7 @@ var (
|
||||||
GasPriceFlag = BigFlag{
|
GasPriceFlag = BigFlag{
|
||||||
Name: "gasprice",
|
Name: "gasprice",
|
||||||
Usage: "Minimal gas price to accept for mining a transactions",
|
Usage: "Minimal gas price to accept for mining a transactions",
|
||||||
Value: eth.DefaultConfig.GasPrice,
|
Value: ethconfig.Defaults.GasPrice,
|
||||||
}
|
}
|
||||||
ExtraDataFlag = cli.StringFlag{
|
ExtraDataFlag = cli.StringFlag{
|
||||||
Name: "extradata",
|
Name: "extradata",
|
||||||
|
|
@ -361,7 +361,12 @@ var (
|
||||||
RPCGlobalGasCapFlag = cli.Uint64Flag{
|
RPCGlobalGasCapFlag = cli.Uint64Flag{
|
||||||
Name: "rpc.gascap",
|
Name: "rpc.gascap",
|
||||||
Usage: "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)",
|
Usage: "Sets a cap on gas that can be used in eth_call/estimateGas (0=infinite)",
|
||||||
Value: eth.DefaultConfig.RPCGasCap,
|
Value: ethconfig.Defaults.RPCGasCap,
|
||||||
|
}
|
||||||
|
RPCGlobalTxFeeCap = cli.Float64Flag{
|
||||||
|
Name: "rpc.txfeecap",
|
||||||
|
Usage: "Sets a cap on transaction fee (in ether) that can be sent via the RPC APIs (0 = no cap)",
|
||||||
|
Value: ethconfig.Defaults.RPCTxFeeCap,
|
||||||
}
|
}
|
||||||
// Logging and debug settings
|
// Logging and debug settings
|
||||||
EthStatsURLFlag = cli.StringFlag{
|
EthStatsURLFlag = cli.StringFlag{
|
||||||
|
|
@ -543,12 +548,22 @@ var (
|
||||||
GpoBlocksFlag = cli.IntFlag{
|
GpoBlocksFlag = cli.IntFlag{
|
||||||
Name: "gpoblocks",
|
Name: "gpoblocks",
|
||||||
Usage: "Number of recent blocks to check for gas prices",
|
Usage: "Number of recent blocks to check for gas prices",
|
||||||
Value: eth.DefaultConfig.GPO.Blocks,
|
Value: ethconfig.Defaults.GPO.Blocks,
|
||||||
}
|
}
|
||||||
GpoPercentileFlag = cli.IntFlag{
|
GpoPercentileFlag = cli.IntFlag{
|
||||||
Name: "gpopercentile",
|
Name: "gpopercentile",
|
||||||
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
|
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices",
|
||||||
Value: eth.DefaultConfig.GPO.Percentile,
|
Value: ethconfig.Defaults.GPO.Percentile,
|
||||||
|
}
|
||||||
|
GpoMaxGasPriceFlag = cli.Int64Flag{
|
||||||
|
Name: "gpo.maxprice",
|
||||||
|
Usage: "Maximum gas price will be recommended by gpo",
|
||||||
|
Value: ethconfig.Defaults.GPO.MaxPrice.Int64(),
|
||||||
|
}
|
||||||
|
GpoIgnoreGasPriceFlag = cli.Int64Flag{
|
||||||
|
Name: "gpo.ignoreprice",
|
||||||
|
Usage: "Gas price below which gpo will ignore transactions",
|
||||||
|
Value: ethconfig.Defaults.GPO.IgnorePrice.Int64(),
|
||||||
}
|
}
|
||||||
WhisperEnabledFlag = cli.BoolFlag{
|
WhisperEnabledFlag = cli.BoolFlag{
|
||||||
Name: "shh",
|
Name: "shh",
|
||||||
|
|
@ -844,7 +859,7 @@ func MakeAddress(ks *keystore.KeyStore, account string) (accounts.Account, error
|
||||||
|
|
||||||
// setEtherbase retrieves the etherbase either from the directly specified
|
// setEtherbase retrieves the etherbase either from the directly specified
|
||||||
// command line flags or from the keystore if CLI indexed.
|
// command line flags or from the keystore if CLI indexed.
|
||||||
func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
|
func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *ethconfig.Config) {
|
||||||
if ctx.GlobalIsSet(EtherbaseFlag.Name) {
|
if ctx.GlobalIsSet(EtherbaseFlag.Name) {
|
||||||
account, err := MakeAddress(ks, ctx.GlobalString(EtherbaseFlag.Name))
|
account, err := MakeAddress(ks, ctx.GlobalString(EtherbaseFlag.Name))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -973,13 +988,25 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setGPO(ctx *cli.Context, cfg *gasprice.Config) {
|
func setGPO(ctx *cli.Context, cfg *gasprice.Config, light bool) {
|
||||||
|
// If we are running the light client, apply another group
|
||||||
|
// settings for gas oracle.
|
||||||
|
if light {
|
||||||
|
cfg.Blocks = ethconfig.LightClientGPO.Blocks
|
||||||
|
cfg.Percentile = ethconfig.LightClientGPO.Percentile
|
||||||
|
}
|
||||||
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
|
if ctx.GlobalIsSet(GpoBlocksFlag.Name) {
|
||||||
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
|
cfg.Blocks = ctx.GlobalInt(GpoBlocksFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
|
if ctx.GlobalIsSet(GpoPercentileFlag.Name) {
|
||||||
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
|
cfg.Percentile = ctx.GlobalInt(GpoPercentileFlag.Name)
|
||||||
}
|
}
|
||||||
|
if ctx.GlobalIsSet(GpoMaxGasPriceFlag.Name) {
|
||||||
|
cfg.MaxPrice = big.NewInt(ctx.GlobalInt64(GpoMaxGasPriceFlag.Name))
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(GpoIgnoreGasPriceFlag.Name) {
|
||||||
|
cfg.IgnorePrice = big.NewInt(ctx.GlobalInt64(GpoIgnoreGasPriceFlag.Name))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
|
func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
|
||||||
|
|
@ -1015,7 +1042,7 @@ func setTxPool(ctx *cli.Context, cfg *core.TxPoolConfig) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func setEthash(ctx *cli.Context, cfg *eth.Config) {
|
func setEthash(ctx *cli.Context, cfg *ethconfig.Config) {
|
||||||
if ctx.GlobalIsSet(EthashCacheDirFlag.Name) {
|
if ctx.GlobalIsSet(EthashCacheDirFlag.Name) {
|
||||||
cfg.Ethash.CacheDir = ctx.GlobalString(EthashCacheDirFlag.Name)
|
cfg.Ethash.CacheDir = ctx.GlobalString(EthashCacheDirFlag.Name)
|
||||||
}
|
}
|
||||||
|
|
@ -1121,7 +1148,7 @@ func SetXDCXConfig(ctx *cli.Context, cfg *XDCx.Config, XDCDataDir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetEthConfig applies eth-related command line flags to the config.
|
// SetEthConfig applies eth-related command line flags to the config.
|
||||||
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
|
||||||
// Avoid conflicting network flags
|
// Avoid conflicting network flags
|
||||||
checkExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag)
|
checkExclusive(ctx, DeveloperFlag, TestnetFlag, RinkebyFlag)
|
||||||
checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag)
|
checkExclusive(ctx, FastSyncFlag, LightModeFlag, SyncModeFlag)
|
||||||
|
|
@ -1130,7 +1157,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
|
|
||||||
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
ks := stack.AccountManager().Backends(keystore.KeyStoreType)[0].(*keystore.KeyStore)
|
||||||
setEtherbase(ctx, ks, cfg)
|
setEtherbase(ctx, ks, cfg)
|
||||||
setGPO(ctx, &cfg.GPO)
|
setGPO(ctx, &cfg.GPO, ctx.GlobalString(SyncModeFlag.Name) == "light")
|
||||||
setTxPool(ctx, &cfg.TxPool)
|
setTxPool(ctx, &cfg.TxPool)
|
||||||
setEthash(ctx, cfg)
|
setEthash(ctx, cfg)
|
||||||
|
|
||||||
|
|
@ -1171,6 +1198,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
||||||
if ctx.GlobalIsSet(DocRootFlag.Name) {
|
if ctx.GlobalIsSet(DocRootFlag.Name) {
|
||||||
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
||||||
}
|
}
|
||||||
|
if ctx.GlobalIsSet(RPCGlobalTxFeeCap.Name) {
|
||||||
|
cfg.RPCTxFeeCap = ctx.GlobalFloat64(RPCGlobalTxFeeCap.Name)
|
||||||
|
}
|
||||||
if ctx.GlobalIsSet(ExtraDataFlag.Name) {
|
if ctx.GlobalIsSet(ExtraDataFlag.Name) {
|
||||||
cfg.ExtraData = []byte(ctx.GlobalString(ExtraDataFlag.Name))
|
cfg.ExtraData = []byte(ctx.GlobalString(ExtraDataFlag.Name))
|
||||||
}
|
}
|
||||||
|
|
@ -1283,12 +1313,12 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
|
||||||
engine = ethash.NewFaker()
|
engine = ethash.NewFaker()
|
||||||
if !ctx.GlobalBool(FakePoWFlag.Name) {
|
if !ctx.GlobalBool(FakePoWFlag.Name) {
|
||||||
engine = ethash.New(ethash.Config{
|
engine = ethash.New(ethash.Config{
|
||||||
CacheDir: stack.ResolvePath(eth.DefaultConfig.Ethash.CacheDir),
|
CacheDir: stack.ResolvePath(ethconfig.Defaults.Ethash.CacheDir),
|
||||||
CachesInMem: eth.DefaultConfig.Ethash.CachesInMem,
|
CachesInMem: ethconfig.Defaults.Ethash.CachesInMem,
|
||||||
CachesOnDisk: eth.DefaultConfig.Ethash.CachesOnDisk,
|
CachesOnDisk: ethconfig.Defaults.Ethash.CachesOnDisk,
|
||||||
DatasetDir: stack.ResolvePath(eth.DefaultConfig.Ethash.DatasetDir),
|
DatasetDir: stack.ResolvePath(ethconfig.Defaults.Ethash.DatasetDir),
|
||||||
DatasetsInMem: eth.DefaultConfig.Ethash.DatasetsInMem,
|
DatasetsInMem: ethconfig.Defaults.Ethash.DatasetsInMem,
|
||||||
DatasetsOnDisk: eth.DefaultConfig.Ethash.DatasetsOnDisk,
|
DatasetsOnDisk: ethconfig.Defaults.Ethash.DatasetsOnDisk,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Fatalf("Only support XDPoS consensus")
|
Fatalf("Only support XDPoS consensus")
|
||||||
|
|
@ -1298,8 +1328,8 @@ func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chai
|
||||||
}
|
}
|
||||||
cache := &core.CacheConfig{
|
cache := &core.CacheConfig{
|
||||||
Disabled: ctx.GlobalString(GCModeFlag.Name) == "archive",
|
Disabled: ctx.GlobalString(GCModeFlag.Name) == "archive",
|
||||||
TrieNodeLimit: eth.DefaultConfig.TrieCache,
|
TrieNodeLimit: ethconfig.Defaults.TrieCache,
|
||||||
TrieTimeLimit: eth.DefaultConfig.TrieTimeout,
|
TrieTimeLimit: ethconfig.Defaults.TrieTimeout,
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
|
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
|
||||||
cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
|
cache.TrieNodeLimit = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
|
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
||||||
"github.com/XinFinOrg/XDPoSChain/les"
|
"github.com/XinFinOrg/XDPoSChain/les"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
|
|
@ -12,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterEthService adds an Ethereum client to the stack.
|
// RegisterEthService adds an Ethereum client to the stack.
|
||||||
func RegisterEthService(stack *node.Node, cfg *eth.Config) {
|
func RegisterEthService(stack *node.Node, cfg *ethconfig.Config) {
|
||||||
var err error
|
var err error
|
||||||
if cfg.SyncMode == downloader.LightSync {
|
if cfg.SyncMode == downloader.LightSync {
|
||||||
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
|
|
|
||||||
|
|
@ -508,7 +508,7 @@ func (x *XDPoS) CacheNoneTIPSigningTxs(header *types.Header, txs []*types.Transa
|
||||||
signTxs := []*types.Transaction{}
|
signTxs := []*types.Transaction{}
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
if tx.IsSigningTransaction() {
|
if tx.IsSigningTransaction() {
|
||||||
var b uint
|
var b uint64
|
||||||
for _, r := range receipts {
|
for _, r := range receipts {
|
||||||
if r.TxHash == tx.Hash() {
|
if r.TxHash == tx.Hash() {
|
||||||
if len(r.PostState) > 0 {
|
if len(r.PostState) > 0 {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/jsre"
|
"github.com/XinFinOrg/XDPoSChain/internal/jsre"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
)
|
)
|
||||||
|
|
@ -84,7 +85,7 @@ type tester struct {
|
||||||
|
|
||||||
// newTester creates a test environment based on which the console can operate.
|
// newTester creates a test environment based on which the console can operate.
|
||||||
// Please ensure you call Close() on the returned tester to avoid leaks.
|
// Please ensure you call Close() on the returned tester to avoid leaks.
|
||||||
func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
|
func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester {
|
||||||
// Create a temporary storage for the node keys and initialize it
|
// Create a temporary storage for the node keys and initialize it
|
||||||
workspace, err := os.MkdirTemp("", "console-tester-")
|
workspace, err := os.MkdirTemp("", "console-tester-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -96,7 +97,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to create node: %v", err)
|
t.Fatalf("failed to create node: %v", err)
|
||||||
}
|
}
|
||||||
ethConf := ð.Config{
|
ethConf := ðconfig.Config{
|
||||||
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
|
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
|
||||||
Etherbase: common.HexToAddress(testAddress),
|
Etherbase: common.HexToAddress(testAddress),
|
||||||
Ethash: ethash.Config{
|
Ethash: ethash.Config{
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import (
|
||||||
|
|
||||||
var _ = (*logMarshaling)(nil)
|
var _ = (*logMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (l Log) MarshalJSON() ([]byte, error) {
|
func (l Log) MarshalJSON() ([]byte, error) {
|
||||||
type Log struct {
|
type Log struct {
|
||||||
Address common.Address `json:"address" gencodec:"required"`
|
Address common.Address `json:"address" gencodec:"required"`
|
||||||
|
|
@ -19,9 +20,9 @@ func (l Log) MarshalJSON() ([]byte, error) {
|
||||||
Data hexutil.Bytes `json:"data" gencodec:"required"`
|
Data hexutil.Bytes `json:"data" gencodec:"required"`
|
||||||
BlockNumber hexutil.Uint64 `json:"blockNumber"`
|
BlockNumber hexutil.Uint64 `json:"blockNumber"`
|
||||||
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
TxIndex hexutil.Uint `json:"transactionIndex" gencodec:"required"`
|
TxIndex hexutil.Uint `json:"transactionIndex"`
|
||||||
BlockHash common.Hash `json:"blockHash"`
|
BlockHash common.Hash `json:"blockHash"`
|
||||||
Index hexutil.Uint `json:"logIndex" gencodec:"required"`
|
Index hexutil.Uint `json:"logIndex"`
|
||||||
Removed bool `json:"removed"`
|
Removed bool `json:"removed"`
|
||||||
}
|
}
|
||||||
var enc Log
|
var enc Log
|
||||||
|
|
@ -37,6 +38,7 @@ func (l Log) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (l *Log) UnmarshalJSON(input []byte) error {
|
func (l *Log) UnmarshalJSON(input []byte) error {
|
||||||
type Log struct {
|
type Log struct {
|
||||||
Address *common.Address `json:"address" gencodec:"required"`
|
Address *common.Address `json:"address" gencodec:"required"`
|
||||||
|
|
@ -44,9 +46,9 @@ func (l *Log) UnmarshalJSON(input []byte) error {
|
||||||
Data *hexutil.Bytes `json:"data" gencodec:"required"`
|
Data *hexutil.Bytes `json:"data" gencodec:"required"`
|
||||||
BlockNumber *hexutil.Uint64 `json:"blockNumber"`
|
BlockNumber *hexutil.Uint64 `json:"blockNumber"`
|
||||||
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash *common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
TxIndex *hexutil.Uint `json:"transactionIndex" gencodec:"required"`
|
TxIndex *hexutil.Uint `json:"transactionIndex"`
|
||||||
BlockHash *common.Hash `json:"blockHash"`
|
BlockHash *common.Hash `json:"blockHash"`
|
||||||
Index *hexutil.Uint `json:"logIndex" gencodec:"required"`
|
Index *hexutil.Uint `json:"logIndex"`
|
||||||
Removed *bool `json:"removed"`
|
Removed *bool `json:"removed"`
|
||||||
}
|
}
|
||||||
var dec Log
|
var dec Log
|
||||||
|
|
@ -72,17 +74,15 @@ func (l *Log) UnmarshalJSON(input []byte) error {
|
||||||
return errors.New("missing required field 'transactionHash' for Log")
|
return errors.New("missing required field 'transactionHash' for Log")
|
||||||
}
|
}
|
||||||
l.TxHash = *dec.TxHash
|
l.TxHash = *dec.TxHash
|
||||||
if dec.TxIndex == nil {
|
if dec.TxIndex != nil {
|
||||||
return errors.New("missing required field 'transactionIndex' for Log")
|
l.TxIndex = uint(*dec.TxIndex)
|
||||||
}
|
}
|
||||||
l.TxIndex = uint(*dec.TxIndex)
|
|
||||||
if dec.BlockHash != nil {
|
if dec.BlockHash != nil {
|
||||||
l.BlockHash = *dec.BlockHash
|
l.BlockHash = *dec.BlockHash
|
||||||
}
|
}
|
||||||
if dec.Index == nil {
|
if dec.Index != nil {
|
||||||
return errors.New("missing required field 'logIndex' for Log")
|
l.Index = uint(*dec.Index)
|
||||||
}
|
}
|
||||||
l.Index = uint(*dec.Index)
|
|
||||||
if dec.Removed != nil {
|
if dec.Removed != nil {
|
||||||
l.Removed = *dec.Removed
|
l.Removed = *dec.Removed
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
type Receipt struct {
|
type Receipt struct {
|
||||||
Type hexutil.Uint64 `json:"type,omitempty"`
|
Type hexutil.Uint64 `json:"type,omitempty"`
|
||||||
PostState hexutil.Bytes `json:"root"`
|
PostState hexutil.Bytes `json:"root"`
|
||||||
Status hexutil.Uint `json:"status"`
|
Status hexutil.Uint64 `json:"status"`
|
||||||
CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
CumulativeGasUsed hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
||||||
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
||||||
Logs []*Log `json:"logs" gencodec:"required"`
|
Logs []*Log `json:"logs" gencodec:"required"`
|
||||||
|
|
@ -32,7 +32,7 @@ func (r Receipt) MarshalJSON() ([]byte, error) {
|
||||||
var enc Receipt
|
var enc Receipt
|
||||||
enc.Type = hexutil.Uint64(r.Type)
|
enc.Type = hexutil.Uint64(r.Type)
|
||||||
enc.PostState = r.PostState
|
enc.PostState = r.PostState
|
||||||
enc.Status = hexutil.Uint(r.Status)
|
enc.Status = hexutil.Uint64(r.Status)
|
||||||
enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed)
|
enc.CumulativeGasUsed = hexutil.Uint64(r.CumulativeGasUsed)
|
||||||
enc.Bloom = r.Bloom
|
enc.Bloom = r.Bloom
|
||||||
enc.Logs = r.Logs
|
enc.Logs = r.Logs
|
||||||
|
|
@ -50,7 +50,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
type Receipt struct {
|
type Receipt struct {
|
||||||
Type *hexutil.Uint64 `json:"type,omitempty"`
|
Type *hexutil.Uint64 `json:"type,omitempty"`
|
||||||
PostState *hexutil.Bytes `json:"root"`
|
PostState *hexutil.Bytes `json:"root"`
|
||||||
Status *hexutil.Uint `json:"status"`
|
Status *hexutil.Uint64 `json:"status"`
|
||||||
CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
CumulativeGasUsed *hexutil.Uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
||||||
Bloom *Bloom `json:"logsBloom" gencodec:"required"`
|
Bloom *Bloom `json:"logsBloom" gencodec:"required"`
|
||||||
Logs []*Log `json:"logs" gencodec:"required"`
|
Logs []*Log `json:"logs" gencodec:"required"`
|
||||||
|
|
@ -72,7 +72,7 @@ func (r *Receipt) UnmarshalJSON(input []byte) error {
|
||||||
r.PostState = *dec.PostState
|
r.PostState = *dec.PostState
|
||||||
}
|
}
|
||||||
if dec.Status != nil {
|
if dec.Status != nil {
|
||||||
r.Status = uint(*dec.Status)
|
r.Status = uint64(*dec.Status)
|
||||||
}
|
}
|
||||||
if dec.CumulativeGasUsed == nil {
|
if dec.CumulativeGasUsed == nil {
|
||||||
return errors.New("missing required field 'cumulativeGasUsed' for Receipt")
|
return errors.New("missing required field 'cumulativeGasUsed' for Receipt")
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,11 @@ type Log struct {
|
||||||
// hash of the transaction
|
// hash of the transaction
|
||||||
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
TxHash common.Hash `json:"transactionHash" gencodec:"required"`
|
||||||
// index of the transaction in the block
|
// index of the transaction in the block
|
||||||
TxIndex uint `json:"transactionIndex" gencodec:"required"`
|
TxIndex uint `json:"transactionIndex"`
|
||||||
// hash of the block in which the transaction was included
|
// hash of the block in which the transaction was included
|
||||||
BlockHash common.Hash `json:"blockHash"`
|
BlockHash common.Hash `json:"blockHash"`
|
||||||
// index of the log in the receipt
|
// index of the log in the receipt
|
||||||
Index uint `json:"logIndex" gencodec:"required"`
|
Index uint `json:"logIndex"`
|
||||||
|
|
||||||
// The Removed field is true if this log was reverted due to a chain reorganisation.
|
// The Removed field is true if this log was reverted due to a chain reorganisation.
|
||||||
// You must pay attention to this field if you receive logs through a filter query.
|
// You must pay attention to this field if you receive logs through a filter query.
|
||||||
|
|
|
||||||
|
|
@ -41,10 +41,10 @@ var errEmptyTypedReceipt = errors.New("empty typed receipt bytes")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ReceiptStatusFailed is the status code of a transaction if execution failed.
|
// ReceiptStatusFailed is the status code of a transaction if execution failed.
|
||||||
ReceiptStatusFailed = uint(0)
|
ReceiptStatusFailed = uint64(0)
|
||||||
|
|
||||||
// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
|
// ReceiptStatusSuccessful is the status code of a transaction if execution succeeded.
|
||||||
ReceiptStatusSuccessful = uint(1)
|
ReceiptStatusSuccessful = uint64(1)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Receipt represents the results of a transaction.
|
// Receipt represents the results of a transaction.
|
||||||
|
|
@ -52,7 +52,7 @@ type Receipt struct {
|
||||||
// Consensus fields: These fields are defined by the Yellow Paper
|
// Consensus fields: These fields are defined by the Yellow Paper
|
||||||
Type uint8 `json:"type,omitempty"`
|
Type uint8 `json:"type,omitempty"`
|
||||||
PostState []byte `json:"root"`
|
PostState []byte `json:"root"`
|
||||||
Status uint `json:"status"`
|
Status uint64 `json:"status"`
|
||||||
CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
CumulativeGasUsed uint64 `json:"cumulativeGasUsed" gencodec:"required"`
|
||||||
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
||||||
Logs []*Log `json:"logs" gencodec:"required"`
|
Logs []*Log `json:"logs" gencodec:"required"`
|
||||||
|
|
@ -73,7 +73,7 @@ type Receipt struct {
|
||||||
type receiptMarshaling struct {
|
type receiptMarshaling struct {
|
||||||
Type hexutil.Uint64
|
Type hexutil.Uint64
|
||||||
PostState hexutil.Bytes
|
PostState hexutil.Bytes
|
||||||
Status hexutil.Uint
|
Status hexutil.Uint64
|
||||||
CumulativeGasUsed hexutil.Uint64
|
CumulativeGasUsed hexutil.Uint64
|
||||||
GasUsed hexutil.Uint64
|
GasUsed hexutil.Uint64
|
||||||
BlockNumber *hexutil.Big
|
BlockNumber *hexutil.Big
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,10 @@ func (b *EthApiBackend) AccountManager() *accounts.Manager {
|
||||||
return b.eth.AccountManager()
|
return b.eth.AccountManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *EthApiBackend) RPCTxFeeCap() float64 {
|
||||||
|
return b.eth.config.RPCTxFeeCap
|
||||||
|
}
|
||||||
|
|
||||||
func (b *EthApiBackend) BloomStatus() (uint64, uint64) {
|
func (b *EthApiBackend) BloomStatus() (uint64, uint64) {
|
||||||
sections, _, _ := b.eth.bloomIndexer.Sections()
|
sections, _, _ := b.eth.bloomIndexer.Sections()
|
||||||
return params.BloomBitsBlocks, sections
|
return params.BloomBitsBlocks, sections
|
||||||
|
|
|
||||||
|
|
@ -25,15 +25,11 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/XDCx"
|
||||||
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
|
"github.com/XinFinOrg/XDPoSChain/XDCxlending"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/filters"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/hooks"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/rlp"
|
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/accounts"
|
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus"
|
"github.com/XinFinOrg/XDPoSChain/consensus"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
|
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS/utils"
|
||||||
|
|
@ -41,12 +37,13 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/contracts"
|
"github.com/XinFinOrg/XDPoSChain/contracts"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/bloombits"
|
"github.com/XinFinOrg/XDPoSChain/core/bloombits"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/XDCx"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/filters"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/hooks"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/event"
|
"github.com/XinFinOrg/XDPoSChain/event"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
||||||
|
|
@ -55,6 +52,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
"github.com/XinFinOrg/XDPoSChain/p2p"
|
"github.com/XinFinOrg/XDPoSChain/p2p"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rpc"
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -67,7 +65,7 @@ type LesServer interface {
|
||||||
|
|
||||||
// Ethereum implements the Ethereum full node service.
|
// Ethereum implements the Ethereum full node service.
|
||||||
type Ethereum struct {
|
type Ethereum struct {
|
||||||
config *Config
|
config *ethconfig.Config
|
||||||
chainConfig *params.ChainConfig
|
chainConfig *params.ChainConfig
|
||||||
|
|
||||||
// Channel for shutting down the service
|
// Channel for shutting down the service
|
||||||
|
|
@ -112,7 +110,7 @@ func (s *Ethereum) AddLesServer(ls LesServer) {
|
||||||
|
|
||||||
// New creates a new Ethereum object (including the
|
// New creates a new Ethereum object (including the
|
||||||
// initialisation of the common Ethereum object)
|
// initialisation of the common Ethereum object)
|
||||||
func New(ctx *node.ServiceContext, config *Config, XDCXServ *XDCx.XDCX, lendingServ *XDCxlending.Lending) (*Ethereum, error) {
|
func New(ctx *node.ServiceContext, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendingServ *XDCxlending.Lending) (*Ethereum, error) {
|
||||||
if config.SyncMode == downloader.LightSync {
|
if config.SyncMode == downloader.LightSync {
|
||||||
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
|
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
|
||||||
}
|
}
|
||||||
|
|
@ -326,7 +324,7 @@ func makeExtraData(extra []byte) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateDB creates the chain database.
|
// CreateDB creates the chain database.
|
||||||
func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) {
|
func CreateDB(ctx *node.ServiceContext, config *ethconfig.Config, name string) (ethdb.Database, error) {
|
||||||
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
|
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,8 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package eth
|
// Package ethconfig contains the configuration of the ETH and LES protocols.
|
||||||
|
package ethconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -33,8 +34,24 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultConfig contains default settings for use on the Ethereum main net.
|
// FullNodeGPO contains default gasprice oracle settings for full node.
|
||||||
var DefaultConfig = Config{
|
var FullNodeGPO = gasprice.Config{
|
||||||
|
Blocks: 20,
|
||||||
|
Percentile: 60,
|
||||||
|
MaxPrice: gasprice.DefaultMaxPrice,
|
||||||
|
IgnorePrice: gasprice.DefaultIgnorePrice,
|
||||||
|
}
|
||||||
|
|
||||||
|
// LightClientGPO contains default gasprice oracle settings for light client.
|
||||||
|
var LightClientGPO = gasprice.Config{
|
||||||
|
Blocks: 2,
|
||||||
|
Percentile: 60,
|
||||||
|
MaxPrice: gasprice.DefaultMaxPrice,
|
||||||
|
IgnorePrice: gasprice.DefaultIgnorePrice,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defaults contains default settings for use on the Ethereum main net.
|
||||||
|
var Defaults = Config{
|
||||||
SyncMode: downloader.FullSync,
|
SyncMode: downloader.FullSync,
|
||||||
Ethash: ethash.Config{
|
Ethash: ethash.Config{
|
||||||
CacheDir: "ethash",
|
CacheDir: "ethash",
|
||||||
|
|
@ -50,12 +67,10 @@ var DefaultConfig = Config{
|
||||||
TrieTimeout: 5 * time.Minute,
|
TrieTimeout: 5 * time.Minute,
|
||||||
GasPrice: big.NewInt(0.25 * params.Shannon),
|
GasPrice: big.NewInt(0.25 * params.Shannon),
|
||||||
|
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
RPCGasCap: 25000000,
|
RPCGasCap: 25000000,
|
||||||
GPO: gasprice.Config{
|
GPO: FullNodeGPO,
|
||||||
Blocks: 20,
|
RPCTxFeeCap: 1, // 1 ether
|
||||||
Percentile: 60,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
@ -66,14 +81,15 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "windows" {
|
if runtime.GOOS == "windows" {
|
||||||
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
|
Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Ethash")
|
||||||
} else {
|
} else {
|
||||||
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash")
|
Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
|
//go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
|
||||||
|
|
||||||
|
// Config contains configuration options for of the ETH and LES protocols.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// The genesis block, which is inserted if the database is empty.
|
// The genesis block, which is inserted if the database is empty.
|
||||||
// If nil, the Ethereum main net block is used.
|
// If nil, the Ethereum main net block is used.
|
||||||
|
|
@ -118,6 +134,10 @@ type Config struct {
|
||||||
|
|
||||||
// RPCGasCap is the global gas cap for eth-call variants.
|
// RPCGasCap is the global gas cap for eth-call variants.
|
||||||
RPCGasCap uint64
|
RPCGasCap uint64
|
||||||
|
|
||||||
|
// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
|
||||||
|
// send-transction variants. The unit is ether.
|
||||||
|
RPCTxFeeCap float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type configMarshaling struct {
|
type configMarshaling struct {
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
// Code generated by github.com/fjl/gencodec. DO NOT EDIT.
|
||||||
|
|
||||||
package eth
|
package ethconfig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
@ -37,6 +37,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
EnablePreimageRecording bool
|
EnablePreimageRecording bool
|
||||||
DocRoot string `toml:"-"`
|
DocRoot string `toml:"-"`
|
||||||
RPCGasCap uint64
|
RPCGasCap uint64
|
||||||
|
RPCTxFeeCap float64
|
||||||
}
|
}
|
||||||
var enc Config
|
var enc Config
|
||||||
enc.Genesis = c.Genesis
|
enc.Genesis = c.Genesis
|
||||||
|
|
@ -60,6 +61,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||||
enc.DocRoot = c.DocRoot
|
enc.DocRoot = c.DocRoot
|
||||||
enc.RPCGasCap = c.RPCGasCap
|
enc.RPCGasCap = c.RPCGasCap
|
||||||
|
enc.RPCTxFeeCap = c.RPCTxFeeCap
|
||||||
return &enc, nil
|
return &enc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +89,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
EnablePreimageRecording *bool
|
EnablePreimageRecording *bool
|
||||||
DocRoot *string `toml:"-"`
|
DocRoot *string `toml:"-"`
|
||||||
RPCGasCap *uint64
|
RPCGasCap *uint64
|
||||||
|
RPCTxFeeCap *float64
|
||||||
}
|
}
|
||||||
var dec Config
|
var dec Config
|
||||||
if err := unmarshal(&dec); err != nil {
|
if err := unmarshal(&dec); err != nil {
|
||||||
|
|
@ -155,5 +158,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
||||||
if dec.RPCGasCap != nil {
|
if dec.RPCGasCap != nil {
|
||||||
c.RPCGasCap = *dec.RPCGasCap
|
c.RPCGasCap = *dec.RPCGasCap
|
||||||
}
|
}
|
||||||
|
if dec.RPCTxFeeCap != nil {
|
||||||
|
c.RPCTxFeeCap = *dec.RPCTxFeeCap
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -24,120 +24,152 @@ import (
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rpc"
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var maxPrice = big.NewInt(500 * params.Shannon)
|
const sampleNumber = 3 // Number of transactions sampled in a block
|
||||||
|
|
||||||
|
var DefaultMaxPrice = big.NewInt(500 * params.GWei)
|
||||||
|
var DefaultIgnorePrice = big.NewInt(2 * params.Wei)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Blocks int
|
Blocks int
|
||||||
Percentile int
|
Percentile int
|
||||||
Default *big.Int `toml:",omitempty"`
|
Default *big.Int `toml:",omitempty"`
|
||||||
|
MaxPrice *big.Int `toml:",omitempty"`
|
||||||
|
IgnorePrice *big.Int `toml:",omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// OracleBackend includes all necessary background APIs for oracle.
|
||||||
|
type OracleBackend interface {
|
||||||
|
HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error)
|
||||||
|
BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error)
|
||||||
|
ChainConfig() *params.ChainConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Oracle recommends gas prices based on the content of recent
|
// Oracle recommends gas prices based on the content of recent
|
||||||
// blocks. Suitable for both light and full clients.
|
// blocks. Suitable for both light and full clients.
|
||||||
type Oracle struct {
|
type Oracle struct {
|
||||||
backend ethapi.Backend
|
backend OracleBackend
|
||||||
lastHead common.Hash
|
lastHead common.Hash
|
||||||
lastPrice *big.Int
|
lastPrice *big.Int
|
||||||
cacheLock sync.RWMutex
|
maxPrice *big.Int
|
||||||
fetchLock sync.Mutex
|
ignorePrice *big.Int
|
||||||
|
cacheLock sync.RWMutex
|
||||||
|
fetchLock sync.Mutex
|
||||||
|
|
||||||
checkBlocks, maxEmpty, maxBlocks int
|
checkBlocks int
|
||||||
percentile int
|
percentile int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOracle returns a new oracle.
|
// NewOracle returns a new gasprice oracle which can recommend suitable
|
||||||
func NewOracle(backend ethapi.Backend, params Config) *Oracle {
|
// gasprice for newly created transaction.
|
||||||
|
func NewOracle(backend OracleBackend, params Config) *Oracle {
|
||||||
blocks := params.Blocks
|
blocks := params.Blocks
|
||||||
if blocks < 1 {
|
if blocks < 1 {
|
||||||
blocks = 1
|
blocks = 1
|
||||||
|
log.Warn("Sanitizing invalid gasprice oracle sample blocks", "provided", params.Blocks, "updated", blocks)
|
||||||
}
|
}
|
||||||
percent := params.Percentile
|
percent := params.Percentile
|
||||||
if percent < 0 {
|
if percent < 0 {
|
||||||
percent = 0
|
percent = 0
|
||||||
|
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
|
||||||
}
|
}
|
||||||
if percent > 100 {
|
if percent > 100 {
|
||||||
percent = 100
|
percent = 100
|
||||||
|
log.Warn("Sanitizing invalid gasprice oracle sample percentile", "provided", params.Percentile, "updated", percent)
|
||||||
|
}
|
||||||
|
maxPrice := params.MaxPrice
|
||||||
|
if maxPrice == nil || maxPrice.Int64() <= 0 {
|
||||||
|
maxPrice = DefaultMaxPrice
|
||||||
|
log.Warn("Sanitizing invalid gasprice oracle price cap", "provided", params.MaxPrice, "updated", maxPrice)
|
||||||
|
}
|
||||||
|
ignorePrice := params.IgnorePrice
|
||||||
|
if ignorePrice == nil || ignorePrice.Int64() <= 0 {
|
||||||
|
ignorePrice = DefaultIgnorePrice
|
||||||
|
log.Warn("Sanitizing invalid gasprice oracle ignore price", "provided", params.IgnorePrice, "updated", ignorePrice)
|
||||||
|
} else if ignorePrice.Int64() > 0 {
|
||||||
|
log.Info("Gasprice oracle is ignoring threshold set", "threshold", ignorePrice)
|
||||||
}
|
}
|
||||||
return &Oracle{
|
return &Oracle{
|
||||||
backend: backend,
|
backend: backend,
|
||||||
lastPrice: params.Default,
|
lastPrice: params.Default,
|
||||||
|
maxPrice: maxPrice,
|
||||||
|
ignorePrice: ignorePrice,
|
||||||
checkBlocks: blocks,
|
checkBlocks: blocks,
|
||||||
maxEmpty: blocks / 2,
|
|
||||||
maxBlocks: blocks * 5,
|
|
||||||
percentile: percent,
|
percentile: percent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuggestPrice returns the recommended gas price.
|
// SuggestPrice returns the recommended gas price.
|
||||||
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
gpo.cacheLock.RLock()
|
|
||||||
lastHead := gpo.lastHead
|
|
||||||
lastPrice := gpo.lastPrice
|
|
||||||
gpo.cacheLock.RUnlock()
|
|
||||||
|
|
||||||
head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
|
head, _ := gpo.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
|
||||||
headHash := head.Hash()
|
headHash := head.Hash()
|
||||||
|
|
||||||
|
// If the latest gasprice is still available, return it.
|
||||||
|
gpo.cacheLock.RLock()
|
||||||
|
lastHead, lastPrice := gpo.lastHead, gpo.lastPrice
|
||||||
|
gpo.cacheLock.RUnlock()
|
||||||
if headHash == lastHead {
|
if headHash == lastHead {
|
||||||
return lastPrice, nil
|
return lastPrice, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
gpo.fetchLock.Lock()
|
gpo.fetchLock.Lock()
|
||||||
defer gpo.fetchLock.Unlock()
|
defer gpo.fetchLock.Unlock()
|
||||||
|
|
||||||
// try checking the cache again, maybe the last fetch fetched what we need
|
// Try checking the cache again, maybe the last fetch fetched what we need
|
||||||
gpo.cacheLock.RLock()
|
gpo.cacheLock.RLock()
|
||||||
lastHead = gpo.lastHead
|
lastHead, lastPrice = gpo.lastHead, gpo.lastPrice
|
||||||
lastPrice = gpo.lastPrice
|
|
||||||
gpo.cacheLock.RUnlock()
|
gpo.cacheLock.RUnlock()
|
||||||
if headHash == lastHead {
|
if headHash == lastHead {
|
||||||
return lastPrice, nil
|
return lastPrice, nil
|
||||||
}
|
}
|
||||||
|
var (
|
||||||
blockNum := head.Number.Uint64()
|
sent, exp int
|
||||||
ch := make(chan getBlockPricesResult, gpo.checkBlocks)
|
number = head.Number.Uint64()
|
||||||
sent := 0
|
result = make(chan getBlockPricesResult, gpo.checkBlocks)
|
||||||
exp := 0
|
quit = make(chan struct{})
|
||||||
var blockPrices []*big.Int
|
txPrices []*big.Int
|
||||||
for sent < gpo.checkBlocks && blockNum > 0 {
|
)
|
||||||
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(blockNum))), blockNum, ch)
|
for sent < gpo.checkBlocks && number > 0 {
|
||||||
|
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(number))), number, sampleNumber, gpo.ignorePrice, result, quit)
|
||||||
sent++
|
sent++
|
||||||
exp++
|
exp++
|
||||||
blockNum--
|
number--
|
||||||
}
|
}
|
||||||
maxEmpty := gpo.maxEmpty
|
|
||||||
for exp > 0 {
|
for exp > 0 {
|
||||||
res := <-ch
|
res := <-result
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
|
close(quit)
|
||||||
return lastPrice, res.err
|
return lastPrice, res.err
|
||||||
}
|
}
|
||||||
exp--
|
exp--
|
||||||
if res.price != nil {
|
// Nothing returned. There are two special cases here:
|
||||||
blockPrices = append(blockPrices, res.price)
|
// - The block is empty
|
||||||
continue
|
// - All the transactions included are sent by the miner itself.
|
||||||
|
// In these cases, use the latest calculated price for samping.
|
||||||
|
if len(res.prices) == 0 {
|
||||||
|
res.prices = []*big.Int{lastPrice}
|
||||||
}
|
}
|
||||||
if maxEmpty > 0 {
|
// Besides, in order to collect enough data for sampling, if nothing
|
||||||
maxEmpty--
|
// meaningful returned, try to query more blocks. But the maximum
|
||||||
continue
|
// is 2*checkBlocks.
|
||||||
}
|
if len(res.prices) == 1 && len(txPrices)+1+exp < gpo.checkBlocks*2 && number > 0 {
|
||||||
if blockNum > 0 && sent < gpo.maxBlocks {
|
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(number))), number, sampleNumber, gpo.ignorePrice, result, quit)
|
||||||
go gpo.getBlockPrices(ctx, types.MakeSigner(gpo.backend.ChainConfig(), big.NewInt(int64(blockNum))), blockNum, ch)
|
|
||||||
sent++
|
sent++
|
||||||
exp++
|
exp++
|
||||||
blockNum--
|
number--
|
||||||
}
|
}
|
||||||
|
txPrices = append(txPrices, res.prices...)
|
||||||
}
|
}
|
||||||
price := lastPrice
|
price := lastPrice
|
||||||
if len(blockPrices) > 0 {
|
if len(txPrices) > 0 {
|
||||||
sort.Sort(bigIntArray(blockPrices))
|
sort.Sort(bigIntArray(txPrices))
|
||||||
price = blockPrices[(len(blockPrices)-1)*gpo.percentile/100]
|
price = txPrices[(len(txPrices)-1)*gpo.percentile/100]
|
||||||
}
|
}
|
||||||
if price.Cmp(maxPrice) > 0 {
|
if price.Cmp(gpo.maxPrice) > 0 {
|
||||||
price = new(big.Int).Set(maxPrice)
|
price = new(big.Int).Set(gpo.maxPrice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check gas price min.
|
// Check gas price min.
|
||||||
|
|
@ -154,8 +186,8 @@ func (gpo *Oracle) SuggestPrice(ctx context.Context) (*big.Int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type getBlockPricesResult struct {
|
type getBlockPricesResult struct {
|
||||||
price *big.Int
|
prices []*big.Int
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
type transactionsByGasPrice []*types.Transaction
|
type transactionsByGasPrice []*types.Transaction
|
||||||
|
|
@ -165,27 +197,40 @@ func (t transactionsByGasPrice) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
|
||||||
func (t transactionsByGasPrice) Less(i, j int) bool { return t[i].GasPriceCmp(t[j]) < 0 }
|
func (t transactionsByGasPrice) Less(i, j int) bool { return t[i].GasPriceCmp(t[j]) < 0 }
|
||||||
|
|
||||||
// getBlockPrices calculates the lowest transaction gas price in a given block
|
// getBlockPrices calculates the lowest transaction gas price in a given block
|
||||||
// and sends it to the result channel. If the block is empty, price is nil.
|
// and sends it to the result channel. If the block is empty or all transactions
|
||||||
func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, blockNum uint64, ch chan getBlockPricesResult) {
|
// are sent by the miner itself(it doesn't make any sense to include this kind of
|
||||||
|
// transaction prices for sampling), nil gasprice is returned.
|
||||||
|
func (gpo *Oracle) getBlockPrices(ctx context.Context, signer types.Signer, blockNum uint64, limit int, ignoreUnder *big.Int, result chan getBlockPricesResult, quit chan struct{}) {
|
||||||
block, err := gpo.backend.BlockByNumber(ctx, rpc.BlockNumber(blockNum))
|
block, err := gpo.backend.BlockByNumber(ctx, rpc.BlockNumber(blockNum))
|
||||||
if block == nil {
|
if block == nil {
|
||||||
ch <- getBlockPricesResult{nil, err}
|
select {
|
||||||
|
case result <- getBlockPricesResult{nil, err}:
|
||||||
|
case <-quit:
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
blockTxs := block.Transactions()
|
blockTxs := block.Transactions()
|
||||||
txs := make([]*types.Transaction, len(blockTxs))
|
txs := make([]*types.Transaction, len(blockTxs))
|
||||||
copy(txs, blockTxs)
|
copy(txs, blockTxs)
|
||||||
sort.Sort(transactionsByGasPrice(txs))
|
sort.Sort(transactionsByGasPrice(txs))
|
||||||
|
|
||||||
|
var prices []*big.Int
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
|
if ignoreUnder != nil && tx.GasPrice().Cmp(ignoreUnder) == -1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
sender, err := types.Sender(signer, tx)
|
sender, err := types.Sender(signer, tx)
|
||||||
if err == nil && sender != block.Coinbase() {
|
if err == nil && sender != block.Coinbase() {
|
||||||
ch <- getBlockPricesResult{tx.GasPrice(), nil}
|
prices = append(prices, tx.GasPrice())
|
||||||
return
|
if len(prices) >= limit {
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ch <- getBlockPricesResult{nil, nil}
|
select {
|
||||||
|
case result <- getBlockPricesResult{prices, nil}:
|
||||||
|
case <-quit:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type bigIntArray []*big.Int
|
type bigIntArray []*big.Int
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,16 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/state"
|
"github.com/XinFinOrg/XDPoSChain/core/state"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/event"
|
"github.com/XinFinOrg/XDPoSChain/event"
|
||||||
"github.com/XinFinOrg/XDPoSChain/p2p"
|
"github.com/XinFinOrg/XDPoSChain/p2p"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
|
|
@ -477,7 +477,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool
|
||||||
genesis = gspec.MustCommit(db)
|
genesis = gspec.MustCommit(db)
|
||||||
blockchain, _ = core.NewBlockChain(db, nil, config, pow, vm.Config{})
|
blockchain, _ = core.NewBlockChain(db, nil, config, pow, vm.Config{})
|
||||||
)
|
)
|
||||||
pm, err := NewProtocolManager(config, downloader.FullSync, DefaultConfig.NetworkId, evmux, new(testTxPool), pow, blockchain, db)
|
pm, err := NewProtocolManager(config, downloader.FullSync, ethconfig.Defaults.NetworkId, evmux, new(testTxPool), pow, blockchain, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("failed to start test protocol manager: %v", err)
|
t.Fatalf("failed to start test protocol manager: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,15 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
"github.com/XinFinOrg/XDPoSChain/core/vm"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/event"
|
"github.com/XinFinOrg/XDPoSChain/event"
|
||||||
"github.com/XinFinOrg/XDPoSChain/p2p"
|
"github.com/XinFinOrg/XDPoSChain/p2p"
|
||||||
|
|
@ -68,7 +68,7 @@ func newTestProtocolManager(mode downloader.SyncMode, blocks int, generator func
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pm, err := NewProtocolManager(gspec.Config, mode, DefaultConfig.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db)
|
pm, err := NewProtocolManager(gspec.Config, mode, ethconfig.Defaults.NetworkId, evmux, &testTxPool{added: newtx}, engine, blockchain, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +183,7 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te
|
||||||
func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesis common.Hash) {
|
func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesis common.Hash) {
|
||||||
msg := &statusData{
|
msg := &statusData{
|
||||||
ProtocolVersion: uint32(p.version),
|
ProtocolVersion: uint32(p.version),
|
||||||
NetworkId: DefaultConfig.NetworkId,
|
NetworkId: ethconfig.Defaults.NetworkId,
|
||||||
TD: td,
|
TD: td,
|
||||||
CurrentBlock: head,
|
CurrentBlock: head,
|
||||||
GenesisBlock: genesis,
|
GenesisBlock: genesis,
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/crypto"
|
"github.com/XinFinOrg/XDPoSChain/crypto"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/p2p"
|
"github.com/XinFinOrg/XDPoSChain/p2p"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rlp"
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
||||||
)
|
)
|
||||||
|
|
@ -59,7 +60,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
|
||||||
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
|
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: StatusMsg, data: statusData{10, DefaultConfig.NetworkId, td, head.Hash(), genesis.Hash()},
|
code: StatusMsg, data: statusData{10, ethconfig.Defaults.NetworkId, td, head.Hash(), genesis.Hash()},
|
||||||
wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol),
|
wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -67,7 +68,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
|
||||||
wantError: errResp(ErrNetworkIdMismatch, "999 (!= 88)"),
|
wantError: errResp(ErrNetworkIdMismatch, "999 (!= 88)"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
code: StatusMsg, data: statusData{uint32(protocol), DefaultConfig.NetworkId, td, head.Hash(), common.Hash{3}},
|
code: StatusMsg, data: statusData{uint32(protocol), ethconfig.Defaults.NetworkId, td, head.Hash(), common.Hash{3}},
|
||||||
wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis.Hash().Bytes()[:8]),
|
wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis.Hash().Bytes()[:8]),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -273,10 +273,15 @@ func (ec *Client) GetTransactionReceiptResult(ctx context.Context, txHash common
|
||||||
}
|
}
|
||||||
return r, result, err
|
return r, result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func toBlockNumArg(number *big.Int) string {
|
func toBlockNumArg(number *big.Int) string {
|
||||||
if number == nil {
|
if number == nil {
|
||||||
return "latest"
|
return "latest"
|
||||||
}
|
}
|
||||||
|
pending := big.NewInt(-1)
|
||||||
|
if number.Cmp(pending) == 0 {
|
||||||
|
return "pending"
|
||||||
|
}
|
||||||
return hexutil.EncodeBig(number)
|
return hexutil.EncodeBig(number)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -412,6 +412,10 @@ func (s *PrivateAccountAPI) SignTransaction(ctx context.Context, args SendTxArgs
|
||||||
if args.Nonce == nil {
|
if args.Nonce == nil {
|
||||||
return nil, errors.New("nonce not specified")
|
return nil, errors.New("nonce not specified")
|
||||||
}
|
}
|
||||||
|
// Before actually sign the transaction, ensure the transaction fee is reasonable.
|
||||||
|
if err := checkTxFee(args.GasPrice.ToInt(), uint64(*args.Gas), s.b.RPCTxFeeCap()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
signed, err := s.signTransaction(ctx, args, passwd)
|
signed, err := s.signTransaction(ctx, args, passwd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Failed transaction sign attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
|
log.Warn("Failed transaction sign attempt", "from", args.From, "to", args.To, "value", args.Value.ToInt(), "err", err)
|
||||||
|
|
@ -2372,6 +2376,12 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c
|
||||||
if tx.To() != nil && tx.IsSpecialTransaction() {
|
if tx.To() != nil && tx.IsSpecialTransaction() {
|
||||||
return common.Hash{}, errors.New("Dont allow transaction sent to BlockSigners & RandomizeSMC smart contract via API")
|
return common.Hash{}, errors.New("Dont allow transaction sent to BlockSigners & RandomizeSMC smart contract via API")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the transaction fee cap is already specified, ensure the
|
||||||
|
// fee of the given transaction is _reasonable_.
|
||||||
|
if err := checkTxFee(tx.GasPrice(), tx.Gas(), b.RPCTxFeeCap()); err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
if err := b.SendTx(ctx, tx); err != nil {
|
if err := b.SendTx(ctx, tx); err != nil {
|
||||||
return common.Hash{}, err
|
return common.Hash{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -3359,6 +3369,10 @@ func (s *PublicTransactionPoolAPI) SignTransaction(ctx context.Context, args Sen
|
||||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// Before actually sign the transaction, ensure the transaction fee is reasonable.
|
||||||
|
if err := checkTxFee(args.GasPrice.ToInt(), uint64(*args.Gas), s.b.RPCTxFeeCap()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
tx, err := s.sign(args.From, args.toTransaction())
|
tx, err := s.sign(args.From, args.toTransaction())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -3404,6 +3418,19 @@ func (s *PublicTransactionPoolAPI) Resend(ctx context.Context, sendArgs SendTxAr
|
||||||
}
|
}
|
||||||
matchTx := sendArgs.toTransaction()
|
matchTx := sendArgs.toTransaction()
|
||||||
|
|
||||||
|
// Before replacing the old transaction, ensure the _new_ transaction fee is reasonable.
|
||||||
|
var price = matchTx.GasPrice()
|
||||||
|
if gasPrice != nil {
|
||||||
|
price = gasPrice.ToInt()
|
||||||
|
}
|
||||||
|
var gas = matchTx.Gas()
|
||||||
|
if gasLimit != nil {
|
||||||
|
gas = uint64(*gasLimit)
|
||||||
|
}
|
||||||
|
if err := checkTxFee(price, gas, s.b.RPCTxFeeCap()); err != nil {
|
||||||
|
return common.Hash{}, err
|
||||||
|
}
|
||||||
|
|
||||||
// Iterate the pending list for replacement
|
// Iterate the pending list for replacement
|
||||||
pending, err := s.b.GetPoolTransactions()
|
pending, err := s.b.GetPoolTransactions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -3553,6 +3580,21 @@ func (s *PublicNetAPI) Version() string {
|
||||||
return fmt.Sprintf("%d", s.networkVersion)
|
return fmt.Sprintf("%d", s.networkVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// checkTxFee is an internal function used to check whether the fee of
|
||||||
|
// the given transaction is _reasonable_(under the cap).
|
||||||
|
func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
|
||||||
|
// Short circuit if there is no cap for transaction fee at all.
|
||||||
|
if cap == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(params.Ether)))
|
||||||
|
feeFloat, _ := feeEth.Float64()
|
||||||
|
if feeFloat > cap {
|
||||||
|
return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetSignersFromBlocks(b Backend, blockNumber uint64, blockHash common.Hash, masternodes []common.Address) ([]common.Address, error) {
|
func GetSignersFromBlocks(b Backend, blockNumber uint64, blockHash common.Hash, masternodes []common.Address) ([]common.Address, error) {
|
||||||
var addrs []common.Address
|
var addrs []common.Address
|
||||||
mapMN := map[common.Address]bool{}
|
mapMN := map[common.Address]bool{}
|
||||||
|
|
@ -3653,18 +3695,3 @@ func (s *PublicBlockChainAPI) GetStakerROIMasternode(masternode common.Address)
|
||||||
|
|
||||||
return 100.0 / float64(totalCap.Div(totalCap, voterRewardAYear).Uint64())
|
return 100.0 / float64(totalCap.Div(totalCap, voterRewardAYear).Uint64())
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkTxFee is an internal function used to check whether the fee of
|
|
||||||
// the given transaction is _reasonable_(under the cap).
|
|
||||||
func checkTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
|
|
||||||
// Short circuit if there is no cap for transaction fee at all.
|
|
||||||
if cap == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
feeEth := new(big.Float).Quo(new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas))), new(big.Float).SetInt(big.NewInt(params.Ether)))
|
|
||||||
feeFloat, _ := feeEth.Float64()
|
|
||||||
if feeFloat > cap {
|
|
||||||
return fmt.Errorf("tx fee (%.2f ether) exceeds the configured cap (%.2f ether)", feeFloat, cap)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ type Backend interface {
|
||||||
EventMux() *event.TypeMux
|
EventMux() *event.TypeMux
|
||||||
AccountManager() *accounts.Manager
|
AccountManager() *accounts.Manager
|
||||||
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
|
RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection
|
||||||
|
RPCTxFeeCap() float64 // global tx fee cap for all transaction related APIs
|
||||||
XDCxService() *XDCx.XDCX
|
XDCxService() *XDCx.XDCX
|
||||||
LendingService() *XDCxlending.Lending
|
LendingService() *XDCxlending.Lending
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -273,6 +273,10 @@ func (b *LesApiBackend) RPCGasCap() uint64 {
|
||||||
return b.eth.config.RPCGasCap
|
return b.eth.config.RPCGasCap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *LesApiBackend) RPCTxFeeCap() float64 {
|
||||||
|
return b.eth.config.RPCTxFeeCap
|
||||||
|
}
|
||||||
|
|
||||||
func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
|
func (b *LesApiBackend) BloomStatus() (uint64, uint64) {
|
||||||
if b.eth.bloomIndexer == nil {
|
if b.eth.bloomIndexer == nil {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/filters"
|
"github.com/XinFinOrg/XDPoSChain/eth/filters"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
"github.com/XinFinOrg/XDPoSChain/eth/gasprice"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
|
|
@ -46,7 +47,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type LightEthereum struct {
|
type LightEthereum struct {
|
||||||
config *eth.Config
|
config *ethconfig.Config
|
||||||
|
|
||||||
odr *LesOdr
|
odr *LesOdr
|
||||||
relay *LesTxRelay
|
relay *LesTxRelay
|
||||||
|
|
@ -79,7 +80,7 @@ type LightEthereum struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
func New(ctx *node.ServiceContext, config *ethconfig.Config) (*LightEthereum, error) {
|
||||||
chainDb, err := eth.CreateDB(ctx, config, "lightchaindata")
|
chainDb, err := eth.CreateDB(ctx, config, "lightchaindata")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/les/flowcontrol"
|
"github.com/XinFinOrg/XDPoSChain/les/flowcontrol"
|
||||||
"github.com/XinFinOrg/XDPoSChain/light"
|
"github.com/XinFinOrg/XDPoSChain/light"
|
||||||
|
|
@ -37,7 +38,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type LesServer struct {
|
type LesServer struct {
|
||||||
config *eth.Config
|
config *ethconfig.Config
|
||||||
protocolManager *ProtocolManager
|
protocolManager *ProtocolManager
|
||||||
fcManager *flowcontrol.ClientManager // nil if our node is client only
|
fcManager *flowcontrol.ClientManager // nil if our node is client only
|
||||||
fcCostStats *requestCostStats
|
fcCostStats *requestCostStats
|
||||||
|
|
@ -49,7 +50,7 @@ type LesServer struct {
|
||||||
chtIndexer, bloomTrieIndexer *core.ChainIndexer
|
chtIndexer, bloomTrieIndexer *core.ChainIndexer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLesServer(eth *eth.Ethereum, config *eth.Config) (*LesServer, error) {
|
func NewLesServer(eth *eth.Ethereum, config *ethconfig.Config) (*LesServer, error) {
|
||||||
quitSync := make(chan struct{})
|
quitSync := make(chan struct{})
|
||||||
pm, err := NewProtocolManager(eth.BlockChain().Config(), false, ServerProtocolVersions, config.NetworkId, eth.EventMux(), eth.Engine(), newPeerSet(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil, quitSync, new(sync.WaitGroup))
|
pm, err := NewProtocolManager(eth.BlockChain().Config(), false, ServerProtocolVersions, config.NetworkId, eth.EventMux(), eth.Engine(), newPeerSet(), eth.BlockChain(), eth.TxPool(), eth.ChainDb(), nil, nil, quitSync, new(sync.WaitGroup))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ type signer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *signer) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
|
func (s *signer) Sign(addr *Address, unsignedTx *Transaction) (signedTx *Transaction, _ error) {
|
||||||
sig, err := s.sign(types.HomesteadSigner{}, addr.address, unsignedTx.tx)
|
sig, err := s.sign(addr.address, unsignedTx.tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ func (opts *TransactOpts) GetGasLimit() int64 { return int64(opts.opts.GasLimi
|
||||||
func (opts *TransactOpts) SetFrom(from *Address) { opts.opts.From = from.address }
|
func (opts *TransactOpts) SetFrom(from *Address) { opts.opts.From = from.address }
|
||||||
func (opts *TransactOpts) SetNonce(nonce int64) { opts.opts.Nonce = big.NewInt(nonce) }
|
func (opts *TransactOpts) SetNonce(nonce int64) { opts.opts.Nonce = big.NewInt(nonce) }
|
||||||
func (opts *TransactOpts) SetSigner(s Signer) {
|
func (opts *TransactOpts) SetSigner(s Signer) {
|
||||||
opts.opts.Signer = func(signer types.Signer, addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
opts.opts.Signer = func(addr common.Address, tx *types.Transaction) (*types.Transaction, error) {
|
||||||
sig, err := s.Sign(&Address{addr}, &Transaction{tx})
|
sig, err := s.Sign(&Address{addr}, &Transaction{tx})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/core"
|
"github.com/XinFinOrg/XDPoSChain/core"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethclient"
|
"github.com/XinFinOrg/XDPoSChain/ethclient"
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
"github.com/XinFinOrg/XDPoSChain/ethstats"
|
||||||
"github.com/XinFinOrg/XDPoSChain/les"
|
"github.com/XinFinOrg/XDPoSChain/les"
|
||||||
|
|
@ -144,7 +144,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
|
||||||
}
|
}
|
||||||
// Register the Ethereum protocol if requested
|
// Register the Ethereum protocol if requested
|
||||||
if config.EthereumEnabled {
|
if config.EthereumEnabled {
|
||||||
ethConf := eth.DefaultConfig
|
ethConf := ethconfig.Defaults
|
||||||
ethConf.Genesis = genesis
|
ethConf.Genesis = genesis
|
||||||
ethConf.SyncMode = downloader.LightSync
|
ethConf.SyncMode = downloader.LightSync
|
||||||
ethConf.NetworkId = uint64(config.EthereumNetworkID)
|
ethConf.NetworkId = uint64(config.EthereumNetworkID)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ const (
|
||||||
Wei = 1
|
Wei = 1
|
||||||
Ada = 1e3
|
Ada = 1e3
|
||||||
Babbage = 1e6
|
Babbage = 1e6
|
||||||
|
GWei = 1e9
|
||||||
Shannon = 1e9
|
Shannon = 1e9
|
||||||
Szabo = 1e12
|
Szabo = 1e12
|
||||||
Finney = 1e15
|
Finney = 1e15
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue