diff options
author | Felix Lange <fjl@twurst.com> | 2016-11-14 17:52:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-14 17:52:02 +0800 |
commit | ca73dea3b9bcdf3b5424b5c48c70817439e2e304 (patch) | |
tree | 670e2833878e72555644fbbd81db6c5a1b44493f /les | |
parent | 21701190ac0a838e347f31b7a918bb0a60c1e8c1 (diff) | |
parent | 648bd22427000b6e20a5e1a9c397005aa1ad4f9b (diff) | |
download | dexon-ca73dea3b9bcdf3b5424b5c48c70817439e2e304.tar.gz dexon-ca73dea3b9bcdf3b5424b5c48c70817439e2e304.tar.zst dexon-ca73dea3b9bcdf3b5424b5c48c70817439e2e304.zip |
Merge pull request #3179 from obscuren/eip-158
EIP158 & 160 Hardfork
Diffstat (limited to 'les')
-rw-r--r-- | les/api_backend.go | 13 | ||||
-rw-r--r-- | les/backend.go | 8 | ||||
-rw-r--r-- | les/handler.go | 5 | ||||
-rw-r--r-- | les/helper_test.go | 20 | ||||
-rw-r--r-- | les/odr_test.go | 75 |
5 files changed, 41 insertions, 80 deletions
diff --git a/les/api_backend.go b/les/api_backend.go index 04120c669..b77767ed7 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -30,6 +30,7 @@ import ( "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/light" + "github.com/ethereum/go-ethereum/params" rpc "github.com/ethereum/go-ethereum/rpc" "golang.org/x/net/context" ) @@ -39,6 +40,14 @@ type LesApiBackend struct { gpo *gasprice.LightPriceOracle } +func (b *LesApiBackend) ChainConfig() *params.ChainConfig { + return b.eth.chainConfig +} + +func (b *LesApiBackend) CurrentBlock() *types.Block { + return types.NewBlockWithHeader(b.eth.BlockChain().CurrentHeader()) +} + func (b *LesApiBackend) SetHead(number uint64) { b.eth.blockchain.SetHead(number) } @@ -81,13 +90,13 @@ func (b *LesApiBackend) GetTd(blockHash common.Hash) *big.Int { func (b *LesApiBackend) GetVMEnv(ctx context.Context, msg core.Message, state ethapi.State, header *types.Header) (vm.Environment, func() error, error) { stateDb := state.(*light.LightState).Copy() - addr, _ := msg.From() + addr := msg.From() from, err := stateDb.GetOrNewStateObject(ctx, addr) if err != nil { return nil, nil, err } from.SetBalance(common.MaxBig) - env := light.NewEnv(ctx, stateDb, b.eth.chainConfig, b.eth.blockchain, msg, header, b.eth.chainConfig.VmConfig) + env := light.NewEnv(ctx, stateDb, b.eth.chainConfig, b.eth.blockchain, msg, header, vm.Config{}) return env, env.Error, nil } diff --git a/les/backend.go b/les/backend.go index 5eb53d728..1264acfd1 100644 --- a/les/backend.go +++ b/les/backend.go @@ -29,7 +29,6 @@ import ( "github.com/ethereum/go-ethereum/common/httpclient" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/filters" @@ -42,13 +41,14 @@ import ( "github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/params" rpc "github.com/ethereum/go-ethereum/rpc" ) type LightEthereum struct { odr *LesOdr relay *LesTxRelay - chainConfig *core.ChainConfig + chainConfig *params.ChainConfig // Channel for shutting down the service shutdownChan chan bool // Handlers @@ -107,10 +107,6 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) { return nil, errors.New("missing chain config") } eth.chainConfig = config.ChainConfig - eth.chainConfig.VmConfig = vm.Config{ - EnableJit: config.EnableJit, - ForceJit: config.ForceJit, - } eth.blockchain, err = light.NewLightChain(odr, eth.chainConfig, eth.pow, eth.eventMux) if err != nil { if err == core.ErrNoGenesis { diff --git a/les/handler.go b/les/handler.go index 8dca6b24c..a51358676 100644 --- a/les/handler.go +++ b/les/handler.go @@ -38,6 +38,7 @@ import ( "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discv5" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie" @@ -95,7 +96,7 @@ type ProtocolManager struct { txpool txPool txrelay *LesTxRelay networkId int - chainConfig *core.ChainConfig + chainConfig *params.ChainConfig blockchain BlockChain chainDb ethdb.Database odr *LesOdr @@ -129,7 +130,7 @@ type ProtocolManager struct { // NewProtocolManager returns a new ethereum sub protocol manager. The Ethereum sub protocol manages peers capable // with the ethereum network. -func NewProtocolManager(chainConfig *core.ChainConfig, lightSync bool, networkId int, mux *event.TypeMux, pow pow.PoW, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, txrelay *LesTxRelay) (*ProtocolManager, error) { +func NewProtocolManager(chainConfig *params.ChainConfig, lightSync bool, networkId int, mux *event.TypeMux, pow pow.PoW, blockchain BlockChain, txpool txPool, chainDb ethdb.Database, odr *LesOdr, txrelay *LesTxRelay) (*ProtocolManager, error) { // Create the protocol manager with the base fields manager := &ProtocolManager{ lightSync: lightSync, diff --git a/les/helper_test.go b/les/helper_test.go index 1b3c29e48..a5428e954 100644 --- a/les/helper_test.go +++ b/les/helper_test.go @@ -73,20 +73,22 @@ contract test { */ func testChainGen(i int, block *core.BlockGen) { + signer := types.HomesteadSigner{} + switch i { case 0: // In block 1, the test bank sends account #1 some ether. - tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(testBankKey) + tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(10000), params.TxGas, nil, nil).SignECDSA(signer, testBankKey) block.AddTx(tx) case 1: // In block 2, the test bank sends some more ether to account #1. // acc1Addr passes it on to account #2. // acc1Addr creates a test contract. - tx1, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(testBankKey) + tx1, _ := types.NewTransaction(block.TxNonce(testBankAddress), acc1Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(signer, testBankKey) nonce := block.TxNonce(acc1Addr) - tx2, _ := types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(acc1Key) + tx2, _ := types.NewTransaction(nonce, acc2Addr, big.NewInt(1000), params.TxGas, nil, nil).SignECDSA(signer, acc1Key) nonce++ - tx3, _ := types.NewContractCreation(nonce, big.NewInt(0), big.NewInt(200000), big.NewInt(0), testContractCode).SignECDSA(acc1Key) + tx3, _ := types.NewContractCreation(nonce, big.NewInt(0), big.NewInt(200000), big.NewInt(0), testContractCode).SignECDSA(signer, acc1Key) testContractAddr = crypto.CreateAddress(acc1Addr, nonce) block.AddTx(tx1) block.AddTx(tx2) @@ -96,7 +98,7 @@ func testChainGen(i int, block *core.BlockGen) { block.SetCoinbase(acc2Addr) block.SetExtra([]byte("yeehaw")) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001") - tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), big.NewInt(100000), nil, data).SignECDSA(testBankKey) + tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), big.NewInt(100000), nil, data).SignECDSA(signer, testBankKey) block.AddTx(tx) case 3: // Block 4 includes blocks 2 and 3 as uncle headers (with modified extra data). @@ -107,7 +109,7 @@ func testChainGen(i int, block *core.BlockGen) { b3.Extra = []byte("foo") block.AddUncle(b3) data := common.Hex2Bytes("C16431B900000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002") - tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), big.NewInt(100000), nil, data).SignECDSA(testBankKey) + tx, _ := types.NewTransaction(block.TxNonce(testBankAddress), testContractAddr, big.NewInt(0), big.NewInt(100000), nil, data).SignECDSA(signer, testBankKey) block.AddTx(tx) } } @@ -131,7 +133,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor pow = new(core.FakePow) db, _ = ethdb.NewMemDatabase() genesis = core.WriteGenesisBlockForTesting(db, core.GenesisAccount{Address: testBankAddress, Balance: testBankFunds}) - chainConfig = &core.ChainConfig{HomesteadBlock: big.NewInt(0)} // homestead set to 0 because of chain maker + chainConfig = ¶ms.ChainConfig{HomesteadBlock: big.NewInt(0)} // homestead set to 0 because of chain maker odr *LesOdr chain BlockChain ) @@ -141,7 +143,7 @@ func newTestProtocolManager(lightSync bool, blocks int, generator func(int, *cor chain, _ = light.NewLightChain(odr, chainConfig, pow, evmux) } else { blockchain, _ := core.NewBlockChain(db, chainConfig, pow, evmux) - gchain, _ := core.GenerateChain(nil, genesis, db, blocks, generator) + gchain, _ := core.GenerateChain(chainConfig, genesis, db, blocks, generator) if _, err := blockchain.InsertChain(gchain); err != nil { panic(err) } @@ -214,7 +216,7 @@ func (p *testTxPool) GetTransactions() types.Transactions { // newTestTransaction create a new dummy transaction. func newTestTransaction(from *ecdsa.PrivateKey, nonce uint64, datasize int) *types.Transaction { tx := types.NewTransaction(nonce, common.Address{}, big.NewInt(0), big.NewInt(100000), big.NewInt(0), make([]byte, datasize)) - tx, _ = tx.SignECDSA(from) + tx, _ = tx.SignECDSA(types.HomesteadSigner{}, from) return tx } diff --git a/les/odr_test.go b/les/odr_test.go index 3c8ea8c3f..f1fa59ad8 100644 --- a/les/odr_test.go +++ b/les/odr_test.go @@ -26,17 +26,19 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/light" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "golang.org/x/net/context" ) -type odrTestFn func(ctx context.Context, db ethdb.Database, config *core.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte +type odrTestFn func(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte func TestOdrGetBlockLes1(t *testing.T) { testOdr(t, 1, 1, odrGetBlock) } -func odrGetBlock(ctx context.Context, db ethdb.Database, config *core.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { +func odrGetBlock(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { var block *types.Block if bc != nil { block = bc.GetBlockByHash(bhash) @@ -52,7 +54,7 @@ func odrGetBlock(ctx context.Context, db ethdb.Database, config *core.ChainConfi func TestOdrGetReceiptsLes1(t *testing.T) { testOdr(t, 1, 1, odrGetReceipts) } -func odrGetReceipts(ctx context.Context, db ethdb.Database, config *core.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { +func odrGetReceipts(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { var receipts types.Receipts if bc != nil { receipts = core.GetBlockReceipts(db, bhash, core.GetBlockNumber(db, bhash)) @@ -68,7 +70,7 @@ func odrGetReceipts(ctx context.Context, db ethdb.Database, config *core.ChainCo func TestOdrAccountsLes1(t *testing.T) { testOdr(t, 1, 1, odrAccounts) } -func odrAccounts(ctx context.Context, db ethdb.Database, config *core.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { +func odrAccounts(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { dummyAddr := common.HexToAddress("1234567812345678123456781234567812345678") acc := []common.Address{testBankAddress, acc1Addr, acc2Addr, dummyAddr} @@ -98,47 +100,13 @@ func odrAccounts(ctx context.Context, db ethdb.Database, config *core.ChainConfi func TestOdrContractCallLes1(t *testing.T) { testOdr(t, 1, 2, odrContractCall) } -// fullcallmsg is the message type used for call transations. -type fullcallmsg struct { - from *state.StateObject - to *common.Address - gas, gasPrice *big.Int - value *big.Int - data []byte +type callmsg struct { + types.Message } -// accessor boilerplate to implement core.Message -func (m fullcallmsg) From() (common.Address, error) { return m.from.Address(), nil } -func (m fullcallmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil } -func (m fullcallmsg) Nonce() uint64 { return 0 } -func (m fullcallmsg) CheckNonce() bool { return false } -func (m fullcallmsg) To() *common.Address { return m.to } -func (m fullcallmsg) GasPrice() *big.Int { return m.gasPrice } -func (m fullcallmsg) Gas() *big.Int { return m.gas } -func (m fullcallmsg) Value() *big.Int { return m.value } -func (m fullcallmsg) Data() []byte { return m.data } - -// callmsg is the message type used for call transations. -type lightcallmsg struct { - from *light.StateObject - to *common.Address - gas, gasPrice *big.Int - value *big.Int - data []byte -} +func (callmsg) CheckNonce() bool { return false } -// accessor boilerplate to implement core.Message -func (m lightcallmsg) From() (common.Address, error) { return m.from.Address(), nil } -func (m lightcallmsg) FromFrontier() (common.Address, error) { return m.from.Address(), nil } -func (m lightcallmsg) Nonce() uint64 { return 0 } -func (m lightcallmsg) CheckNonce() bool { return false } -func (m lightcallmsg) To() *common.Address { return m.to } -func (m lightcallmsg) GasPrice() *big.Int { return m.gasPrice } -func (m lightcallmsg) Gas() *big.Int { return m.gas } -func (m lightcallmsg) Value() *big.Int { return m.value } -func (m lightcallmsg) Data() []byte { return m.data } - -func odrContractCall(ctx context.Context, db ethdb.Database, config *core.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { +func odrContractCall(ctx context.Context, db ethdb.Database, config *params.ChainConfig, bc *core.BlockChain, lc *light.LightChain, bhash common.Hash) []byte { data := common.Hex2Bytes("60CD26850000000000000000000000000000000000000000000000000000000000000000") var res []byte @@ -151,16 +119,8 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *core.ChainC from := statedb.GetOrNewStateObject(testBankAddress) from.SetBalance(common.MaxBig) - msg := fullcallmsg{ - from: from, - gas: big.NewInt(100000), - gasPrice: big.NewInt(0), - value: big.NewInt(0), - data: data, - to: &testContractAddr, - } - - vmenv := core.NewEnv(statedb, config, bc, msg, header, config.VmConfig) + msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)} + vmenv := core.NewEnv(statedb, config, bc, msg, header, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) ret, _, _ := core.ApplyMessage(vmenv, msg, gp) res = append(res, ret...) @@ -172,16 +132,9 @@ func odrContractCall(ctx context.Context, db ethdb.Database, config *core.ChainC if err == nil { from.SetBalance(common.MaxBig) - msg := lightcallmsg{ - from: from, - gas: big.NewInt(100000), - gasPrice: big.NewInt(0), - value: big.NewInt(0), - data: data, - to: &testContractAddr, - } + msg := callmsg{types.NewMessage(from.Address(), &testContractAddr, 0, new(big.Int), big.NewInt(100000), new(big.Int), data)} - vmenv := light.NewEnv(ctx, state, config, lc, msg, header, config.VmConfig) + vmenv := light.NewEnv(ctx, state, config, lc, msg, header, vm.Config{}) gp := new(core.GasPool).AddGas(common.MaxBig) ret, _, _ := core.ApplyMessage(vmenv, msg, gp) if vmenv.Error() == nil { |