Updating ethereum version from fork (#68)

* syncing with updated ethereum version with local versions

* Revert updates back to go-ethereum v1.8.27

* Fixed chain-test change from undoing recent go-ethereum changes

* Fixes linting issues

* Remove unused interface implementations

* Updates cosmos-sdk version from relative dependency and updates auxiliary changes

* Upgrading ethereum version back to most recent since 1.9 release <:)

* syncing with updated ethereum version with local versions

* Revert updates back to go-ethereum v1.8.27

* Fixed chain-test change from undoing recent go-ethereum changes

* Fixes linting issues

* Remove unused interface implementations

* Updates cosmos-sdk version from relative dependency and updates auxiliary changes

* Upgrading ethereum version back to most recent since 1.9 release <:)

* Added documentation for cloned functions
This commit is contained in:
Austin Abell
2019-07-11 14:05:34 -04:00
committed by GitHub
parent 73cf6d9217
commit 9803c1b80e
9 changed files with 287 additions and 199 deletions
+29 -1
View File
@@ -3,6 +3,7 @@ package types
import (
"bytes"
"fmt"
"io"
"math/big"
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -12,15 +13,37 @@ import (
ethcmn "github.com/ethereum/go-ethereum/common"
ethstate "github.com/ethereum/go-ethereum/core/state"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
)
var (
_ ethstate.StateObject = (*stateObject)(nil)
_ StateObject = (*stateObject)(nil)
emptyCodeHash = ethcrypto.Keccak256(nil)
)
type (
// StateObject interface for interacting with state object
StateObject interface {
GetCommittedState(db ethstate.Database, key ethcmn.Hash) ethcmn.Hash
GetState(db ethstate.Database, key ethcmn.Hash) ethcmn.Hash
SetState(db ethstate.Database, key, value ethcmn.Hash)
Code(db ethstate.Database) []byte
SetCode(codeHash ethcmn.Hash, code []byte)
CodeHash() []byte
AddBalance(amount *big.Int)
SubBalance(amount *big.Int)
SetBalance(amount *big.Int)
Balance() *big.Int
ReturnGas(gas *big.Int)
Address() ethcmn.Address
SetNonce(nonce uint64)
Nonce() uint64
}
// stateObject represents an Ethereum account which is being modified.
//
// The usage pattern is as follows:
@@ -341,6 +364,11 @@ func (so *stateObject) empty() bool {
bytes.Equal(so.account.CodeHash, emptyCodeHash)
}
// EncodeRLP implements rlp.Encoder.
func (so *stateObject) EncodeRLP(w io.Writer) error {
return rlp.Encode(w, so.account)
}
func (so *stateObject) touch() {
so.stateDB.journal.append(touchChange{
account: &so.address,
+31 -14
View File
@@ -12,15 +12,21 @@ import (
ethcmn "github.com/ethereum/go-ethereum/common"
ethstate "github.com/ethereum/go-ethereum/core/state"
ethtypes "github.com/ethereum/go-ethereum/core/types"
ethvm "github.com/ethereum/go-ethereum/core/vm"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
)
var (
_ ethstate.StateDB = (*CommitStateDB)(nil)
_ ethvm.StateDB = (*CommitStateDB)(nil)
zeroBalance = sdk.ZeroInt().BigInt()
)
type revision struct {
id int
journalIndex int
}
// CommitStateDB implements the Geth state.StateDB interface. Instead of using
// a trie and database for querying and persistence, the Keeper uses KVStores
// and an account mapper is used to facilitate state transitions.
@@ -64,7 +70,7 @@ type CommitStateDB struct {
// Journal of state modifications. This is the backbone of
// Snapshot and RevertToSnapshot.
journal *journal
validRevisions []ethstate.Revision
validRevisions []revision
nextRevisionID int
// mutex for state deep copying
@@ -207,6 +213,16 @@ func (csdb *CommitStateDB) GetNonce(addr ethcmn.Address) uint64 {
return 0
}
// TxIndex returns the current transaction index set by Prepare.
func (csdb *CommitStateDB) TxIndex() int {
return csdb.txIndex
}
// BlockHash returns the current block hash set by Prepare.
func (csdb *CommitStateDB) BlockHash() ethcmn.Hash {
return csdb.bhash
}
// GetCode returns the code for a given account.
func (csdb *CommitStateDB) GetCode(addr ethcmn.Address) []byte {
so := csdb.getStateObject(addr)
@@ -354,7 +370,7 @@ func (csdb *CommitStateDB) Commit(deleteEmptyObjects bool) (root ethcmn.Hash, er
// Finalize finalizes the state objects (accounts) state by setting their state,
// removing the csdb destructed objects and clearing the journal as well as the
// refunds.
func (csdb *CommitStateDB) Finalize(deleteEmptyObjects bool) {
func (csdb *CommitStateDB) Finalise(deleteEmptyObjects bool) {
for addr := range csdb.journal.dirties {
so, exist := csdb.stateObjects[addr]
if !exist {
@@ -394,7 +410,7 @@ func (csdb *CommitStateDB) Finalize(deleteEmptyObjects bool) {
// root as commitment of the merkle-ized tree doesn't happen until the
// BaseApps' EndBlocker.
func (csdb *CommitStateDB) IntermediateRoot(deleteEmptyObjects bool) ethcmn.Hash {
csdb.Finalize(deleteEmptyObjects)
csdb.Finalise(deleteEmptyObjects)
return ethcmn.Hash{}
}
@@ -421,9 +437,9 @@ func (csdb *CommitStateDB) Snapshot() int {
csdb.validRevisions = append(
csdb.validRevisions,
ethstate.Revision{
ID: id,
JournalIndex: csdb.journal.length(),
revision{
id: id,
journalIndex: csdb.journal.length(),
},
)
@@ -434,14 +450,14 @@ func (csdb *CommitStateDB) Snapshot() int {
func (csdb *CommitStateDB) RevertToSnapshot(revID int) {
// find the snapshot in the stack of valid snapshots
idx := sort.Search(len(csdb.validRevisions), func(i int) bool {
return csdb.validRevisions[i].ID >= revID
return csdb.validRevisions[i].id >= revID
})
if idx == len(csdb.validRevisions) || csdb.validRevisions[idx].ID != revID {
if idx == len(csdb.validRevisions) || csdb.validRevisions[idx].id != revID {
panic(fmt.Errorf("revision ID %v cannot be reverted", revID))
}
snapshot := csdb.validRevisions[idx].JournalIndex
snapshot := csdb.validRevisions[idx].journalIndex
// replay the journal to undo changes and remove invalidated snapshots
csdb.journal.revert(csdb, snapshot)
@@ -549,7 +565,7 @@ func (csdb *CommitStateDB) CreateAccount(addr ethcmn.Address) {
// Copy creates a deep, independent copy of the state.
//
// NOTE: Snapshots of the copied state cannot be applied to the copy.
func (csdb *CommitStateDB) Copy() ethstate.StateDB {
func (csdb *CommitStateDB) Copy() ethvm.StateDB {
csdb.lock.Lock()
defer csdb.lock.Unlock()
@@ -611,10 +627,10 @@ func (csdb *CommitStateDB) Copy() ethstate.StateDB {
// ForEachStorage iterates over each storage items, all invokes the provided
// callback on each key, value pair .
func (csdb *CommitStateDB) ForEachStorage(addr ethcmn.Address, cb func(key, value ethcmn.Hash) bool) {
func (csdb *CommitStateDB) ForEachStorage(addr ethcmn.Address, cb func(key, value ethcmn.Hash) bool) error {
so := csdb.getStateObject(addr)
if so == nil {
return
return nil
}
store := csdb.ctx.KVStore(csdb.storageKey)
@@ -633,11 +649,12 @@ func (csdb *CommitStateDB) ForEachStorage(addr ethcmn.Address, cb func(key, valu
}
iter.Close()
return nil
}
// GetOrNewStateObject retrieves a state object or create a new state object if
// nil.
func (csdb *CommitStateDB) GetOrNewStateObject(addr ethcmn.Address) ethstate.StateObject {
func (csdb *CommitStateDB) GetOrNewStateObject(addr ethcmn.Address) StateObject {
so := csdb.getStateObject(addr)
if so == nil || so.deleted {
so, _ = csdb.createObject(addr)
+3 -3
View File
@@ -6,10 +6,10 @@ import (
"github.com/cosmos/ethermint/crypto"
ethcmn "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
ethsha "github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/rlp"
"github.com/pkg/errors"
"golang.org/x/crypto/sha3"
)
// GenerateEthAddress generates an Ethereum address.
@@ -38,11 +38,11 @@ func ValidateSigner(signBytes, sig []byte, signer ethcmn.Address) error {
}
func rlpHash(x interface{}) (hash ethcmn.Hash) {
hasher := ethsha.NewKeccak256()
hasher := sha3.NewLegacyKeccak256()
// nolint:errcheck
rlp.Encode(hasher, x)
hasher.Sum(hash[:0])
return
return hash
}