Skip to content

Commit 7330889

Browse files
authored
Merge pull request #559 from gzliudan/eip1559-1
some PR before EIP-1559
2 parents a944232 + f445196 commit 7330889

File tree

35 files changed

+429
-199
lines changed

35 files changed

+429
-199
lines changed

accounts/abi/bind/auth.go

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,29 @@ import (
2020
"crypto/ecdsa"
2121
"errors"
2222
"io"
23+
"io/ioutil"
24+
"math/big"
2325

26+
"github.com/XinFinOrg/XDPoSChain/accounts"
2427
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
2528
"github.com/XinFinOrg/XDPoSChain/common"
2629
"github.com/XinFinOrg/XDPoSChain/core/types"
2730
"github.com/XinFinOrg/XDPoSChain/crypto"
31+
"github.com/XinFinOrg/XDPoSChain/log"
2832
)
2933

34+
// ErrNoChainID is returned whenever the user failed to specify a chain id.
35+
var ErrNoChainID = errors.New("no chain id specified")
36+
37+
// ErrNotAuthorized is returned when an account is not properly unlocked.
38+
var ErrNotAuthorized = errors.New("not authorized to sign this account")
39+
3040
// NewTransactor is a utility method to easily create a transaction signer from
3141
// an encrypted json key stream and the associated passphrase.
42+
//
43+
// Deprecated: Use NewTransactorWithChainID instead.
3244
func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
45+
log.Warn("WARNING: NewTransactor has been deprecated in favour of NewTransactorWithChainID")
3346
json, err := io.ReadAll(keyin)
3447
if err != nil {
3548
return nil, err
@@ -43,13 +56,17 @@ func NewTransactor(keyin io.Reader, passphrase string) (*TransactOpts, error) {
4356

4457
// NewKeyedTransactor is a utility method to easily create a transaction signer
4558
// from a single private key.
59+
//
60+
// Deprecated: Use NewKeyedTransactorWithChainID instead.
4661
func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
62+
log.Warn("WARNING: NewKeyedTransactor has been deprecated in favour of NewKeyedTransactorWithChainID")
4763
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
64+
signer := types.HomesteadSigner{}
4865
return &TransactOpts{
4966
From: keyAddr,
50-
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
67+
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
5168
if address != keyAddr {
52-
return nil, errors.New("not authorized to sign this account")
69+
return nil, ErrNotAuthorized
5370
}
5471
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
5572
if err != nil {
@@ -59,3 +76,62 @@ func NewKeyedTransactor(key *ecdsa.PrivateKey) *TransactOpts {
5976
},
6077
}
6178
}
79+
80+
// NewTransactorWithChainID is a utility method to easily create a transaction signer from
81+
// an encrypted json key stream and the associated passphrase.
82+
func NewTransactorWithChainID(keyin io.Reader, passphrase string, chainID *big.Int) (*TransactOpts, error) {
83+
json, err := ioutil.ReadAll(keyin)
84+
if err != nil {
85+
return nil, err
86+
}
87+
key, err := keystore.DecryptKey(json, passphrase)
88+
if err != nil {
89+
return nil, err
90+
}
91+
return NewKeyedTransactorWithChainID(key.PrivateKey, chainID)
92+
}
93+
94+
// NewKeyStoreTransactorWithChainID is a utility method to easily create a transaction signer from
95+
// an decrypted key from a keystore.
96+
func NewKeyStoreTransactorWithChainID(keystore *keystore.KeyStore, account accounts.Account, chainID *big.Int) (*TransactOpts, error) {
97+
if chainID == nil {
98+
return nil, ErrNoChainID
99+
}
100+
signer := types.NewEIP155Signer(chainID)
101+
return &TransactOpts{
102+
From: account.Address,
103+
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
104+
if address != account.Address {
105+
return nil, ErrNotAuthorized
106+
}
107+
signature, err := keystore.SignHash(account, signer.Hash(tx).Bytes())
108+
if err != nil {
109+
return nil, err
110+
}
111+
return tx.WithSignature(signer, signature)
112+
},
113+
}, nil
114+
}
115+
116+
// NewKeyedTransactorWithChainID is a utility method to easily create a transaction signer
117+
// from a single private key.
118+
func NewKeyedTransactorWithChainID(key *ecdsa.PrivateKey, chainID *big.Int) (*TransactOpts, error) {
119+
keyAddr := crypto.PubkeyToAddress(key.PublicKey)
120+
if chainID == nil {
121+
return nil, ErrNoChainID
122+
}
123+
signer := types.NewEIP155Signer(chainID)
124+
return &TransactOpts{
125+
From: keyAddr,
126+
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
127+
if address != keyAddr {
128+
return nil, ErrNotAuthorized
129+
}
130+
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key)
131+
if err != nil {
132+
return nil, err
133+
}
134+
return tx.WithSignature(signer, signature)
135+
},
136+
}, nil
137+
}

accounts/abi/bind/backends/simulated.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi
135135

136136
// NewSimulatedBackend creates a new binding backend using a simulated blockchain
137137
// for testing purposes.
138+
// A simulated backend always uses chainID 1337.
138139
func NewSimulatedBackend(alloc core.GenesisAlloc) *SimulatedBackend {
139140
database := rawdb.NewMemoryDatabase()
140141
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, Alloc: alloc, GasLimit: 42000000}

accounts/abi/bind/base.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ var (
3636

3737
// SignerFn is a signer function callback when a contract requires a method to
3838
// sign the transaction before submission.
39-
type SignerFn func(types.Signer, common.Address, *types.Transaction) (*types.Transaction, error)
39+
type SignerFn func(common.Address, *types.Transaction) (*types.Transaction, error)
4040

4141
// CallOpts is the collection of options to fine tune a contract call request.
4242
type CallOpts struct {
@@ -238,7 +238,7 @@ func (c *BoundContract) transact(opts *TransactOpts, contract *common.Address, i
238238
if opts.Signer == nil {
239239
return nil, errors.New("no signer to authorize the transaction with")
240240
}
241-
signedTx, err := opts.Signer(types.HomesteadSigner{}, opts.From, rawTx)
241+
signedTx, err := opts.Signer(opts.From, rawTx)
242242
if err != nil {
243243
return nil, err
244244
}

accounts/abi/bind/bind_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ var bindTests = []struct {
228228
`
229229
// Generate a new random account and a funded simulator
230230
key, _ := crypto.GenerateKey()
231-
auth := bind.NewKeyedTransactor(key)
231+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
232232
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
233233
234234
// Deploy an interaction tester contract and call a transaction on it
@@ -269,7 +269,7 @@ var bindTests = []struct {
269269
`
270270
// Generate a new random account and a funded simulator
271271
key, _ := crypto.GenerateKey()
272-
auth := bind.NewKeyedTransactor(key)
272+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
273273
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
274274
275275
// Deploy a tuple tester contract and execute a structured call on it
@@ -301,7 +301,7 @@ var bindTests = []struct {
301301
`
302302
// Generate a new random account and a funded simulator
303303
key, _ := crypto.GenerateKey()
304-
auth := bind.NewKeyedTransactor(key)
304+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
305305
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
306306
307307
// Deploy a tuple tester contract and execute a structured call on it
@@ -343,7 +343,7 @@ var bindTests = []struct {
343343
`
344344
// Generate a new random account and a funded simulator
345345
key, _ := crypto.GenerateKey()
346-
auth := bind.NewKeyedTransactor(key)
346+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
347347
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
348348
349349
// Deploy a slice tester contract and execute a n array call on it
@@ -377,7 +377,7 @@ var bindTests = []struct {
377377
`
378378
// Generate a new random account and a funded simulator
379379
key, _ := crypto.GenerateKey()
380-
auth := bind.NewKeyedTransactor(key)
380+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
381381
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
382382
383383
// Deploy a default method invoker contract and execute its default method
@@ -446,7 +446,7 @@ var bindTests = []struct {
446446
`
447447
// Generate a new random account and a funded simulator
448448
key, _ := crypto.GenerateKey()
449-
auth := bind.NewKeyedTransactor(key)
449+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
450450
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
451451
452452
// Deploy a funky gas pattern contract
@@ -481,7 +481,7 @@ var bindTests = []struct {
481481
`
482482
// Generate a new random account and a funded simulator
483483
key, _ := crypto.GenerateKey()
484-
auth := bind.NewKeyedTransactor(key)
484+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
485485
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
486486
487487
// Deploy a sender tester contract and execute a structured call on it
@@ -541,7 +541,7 @@ var bindTests = []struct {
541541
`
542542
// Generate a new random account and a funded simulator
543543
key, _ := crypto.GenerateKey()
544-
auth := bind.NewKeyedTransactor(key)
544+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
545545
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
546546
547547
// Deploy a underscorer tester contract and execute a structured call on it
@@ -611,7 +611,7 @@ var bindTests = []struct {
611611
`
612612
// Generate a new random account and a funded simulator
613613
key, _ := crypto.GenerateKey()
614-
auth := bind.NewKeyedTransactor(key)
614+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
615615
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
616616
617617
// Deploy an eventer contract
@@ -760,7 +760,7 @@ var bindTests = []struct {
760760
`
761761
// Generate a new random account and a funded simulator
762762
key, _ := crypto.GenerateKey()
763-
auth := bind.NewKeyedTransactor(key)
763+
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
764764
sim := backends.NewXDCSimulatedBackend(core.GenesisAlloc{auth.From: {Balance: big.NewInt(10000000000)}}, 10000000, params.TestXDPoSMockChainConfig)
765765
766766
//deploy the test contract

cmd/XDC/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
"github.com/XinFinOrg/XDPoSChain/XDCx"
3333
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
3434
"github.com/XinFinOrg/XDPoSChain/common"
35-
"github.com/XinFinOrg/XDPoSChain/eth"
35+
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
3636
"github.com/XinFinOrg/XDPoSChain/internal/debug"
3737
"github.com/XinFinOrg/XDPoSChain/log"
3838
"github.com/XinFinOrg/XDPoSChain/node"
@@ -90,7 +90,7 @@ type Bootnodes struct {
9090
}
9191

9292
type XDCConfig struct {
93-
Eth eth.Config
93+
Eth ethconfig.Config
9494
Shh whisper.Config
9595
Node node.Config
9696
Ethstats ethstatsConfig
@@ -129,7 +129,7 @@ func defaultNodeConfig() node.Config {
129129
func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) {
130130
// Load defaults.
131131
cfg := XDCConfig{
132-
Eth: eth.DefaultConfig,
132+
Eth: ethconfig.Defaults,
133133
Shh: whisper.DefaultConfig,
134134
XDCX: XDCx.DefaultConfig,
135135
Node: defaultNodeConfig(),

cmd/XDC/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ var (
127127
//utils.NoCompactionFlag,
128128
//utils.GpoBlocksFlag,
129129
//utils.GpoPercentileFlag,
130+
utils.GpoMaxGasPriceFlag,
131+
utils.GpoIgnoreGasPriceFlag,
130132
//utils.ExtraDataFlag,
131133
configFileFlag,
132134
utils.AnnounceTxsFlag,
@@ -148,6 +150,7 @@ var (
148150
utils.WSAllowedOriginsFlag,
149151
utils.IPCDisabledFlag,
150152
utils.IPCPathFlag,
153+
utils.RPCGlobalTxFeeCap,
151154
}
152155

153156
whisperFlags = []cli.Flag{

cmd/XDC/misccmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
2727
"github.com/XinFinOrg/XDPoSChain/consensus/ethash"
2828
"github.com/XinFinOrg/XDPoSChain/eth"
29+
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
2930
"github.com/XinFinOrg/XDPoSChain/params"
3031
"gopkg.in/urfave/cli.v1"
3132
)
@@ -114,7 +115,7 @@ func version(ctx *cli.Context) error {
114115
}
115116
fmt.Println("Architecture:", runtime.GOARCH)
116117
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
117-
fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
118+
fmt.Println("Network Id:", ethconfig.Defaults.NetworkId)
118119
fmt.Println("Go Version:", runtime.Version())
119120
fmt.Println("Operating System:", runtime.GOOS)
120121
fmt.Printf("GOPATH=%s\n", os.Getenv("GOPATH"))

cmd/XDC/usage.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ var AppHelpFlagGroups = []flagGroup{
156156
utils.IPCPathFlag,
157157
utils.RPCCORSDomainFlag,
158158
utils.RPCVirtualHostsFlag,
159+
utils.RPCGlobalTxFeeCap,
159160
utils.JSpathFlag,
160161
utils.ExecFlag,
161162
utils.PreloadJSFlag,
@@ -194,6 +195,8 @@ var AppHelpFlagGroups = []flagGroup{
194195
// Flags: []cli.Flag{
195196
// utils.GpoBlocksFlag,
196197
// utils.GpoPercentileFlag,
198+
// utils.GpoMaxGasPriceFlag,
199+
// utils.GpoIgnoreGasPriceFlag,
197200
// },
198201
//},
199202
//{

cmd/faucet/faucet.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import (
4646
"github.com/XinFinOrg/XDPoSChain/common"
4747
"github.com/XinFinOrg/XDPoSChain/core"
4848
"github.com/XinFinOrg/XDPoSChain/core/types"
49-
"github.com/XinFinOrg/XDPoSChain/eth"
5049
"github.com/XinFinOrg/XDPoSChain/eth/downloader"
50+
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
5151
"github.com/XinFinOrg/XDPoSChain/ethclient"
5252
"github.com/XinFinOrg/XDPoSChain/ethstats"
5353
"github.com/XinFinOrg/XDPoSChain/les"
@@ -239,7 +239,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*discv5.Node, network u
239239
}
240240
// Assemble the Ethereum light client protocol
241241
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
242-
cfg := eth.DefaultConfig
242+
cfg := ethconfig.Defaults
243243
cfg.SyncMode = downloader.LightSync
244244
cfg.NetworkId = network
245245
cfg.Genesis = genesis

cmd/gc/main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
7-
"github.com/XinFinOrg/XDPoSChain/ethdb"
8-
"github.com/XinFinOrg/XDPoSChain/ethdb/leveldb"
96
"os"
107
"os/signal"
118
"runtime"
@@ -16,11 +13,14 @@ import (
1613
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
1714
"github.com/XinFinOrg/XDPoSChain/common"
1815
"github.com/XinFinOrg/XDPoSChain/core"
16+
"github.com/XinFinOrg/XDPoSChain/core/rawdb"
1917
"github.com/XinFinOrg/XDPoSChain/core/state"
20-
"github.com/XinFinOrg/XDPoSChain/eth"
18+
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
19+
"github.com/XinFinOrg/XDPoSChain/ethdb"
20+
"github.com/XinFinOrg/XDPoSChain/ethdb/leveldb"
2121
"github.com/XinFinOrg/XDPoSChain/rlp"
2222
"github.com/XinFinOrg/XDPoSChain/trie"
23-
"github.com/hashicorp/golang-lru"
23+
lru "github.com/hashicorp/golang-lru"
2424
)
2525

2626
var (
@@ -52,7 +52,7 @@ type ResultProcessNode struct {
5252

5353
func main() {
5454
flag.Parse()
55-
db, _ := leveldb.New(*dir, eth.DefaultConfig.DatabaseCache, utils.MakeDatabaseHandles(), "")
55+
db, _ := leveldb.New(*dir, ethconfig.Defaults.DatabaseCache, utils.MakeDatabaseHandles(), "")
5656
lddb := rawdb.NewDatabase(db)
5757
head := core.GetHeadBlockHash(lddb)
5858
currentHeader := core.GetHeader(lddb, head, core.GetBlockNumber(lddb, head))

0 commit comments

Comments
 (0)