Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Remix debugging of EVM call #1496

Closed
wants to merge 54 commits into from
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9bdb94b
wip move middleware to seperate package
Sriep Sep 23, 2019
414db24
implement
Sriep Sep 24, 2019
2b94ec3
wip implement
Sriep Sep 24, 2019
00743d8
implement
Sriep Sep 24, 2019
239fb4b
use ethapi go-ethereum branch
Sriep Sep 25, 2019
04dd303
use config transfer gateway branch
Sriep Sep 25, 2019
79536ea
touch
Sriep Sep 25, 2019
6002221
touch
Sriep Sep 25, 2019
c7af3a8
add version reader
Sriep Sep 25, 2019
343e039
wip use correct chain id
Sriep Sep 27, 2019
af517e5
Merge remote-tracking branch 'remotes/origin/appstate' into debug-evm
Sriep Sep 27, 2019
3d71a4f
move nocetxhandler into loom.go
Sriep Sep 27, 2019
7665fdf
evm debug
Sriep Sep 30, 2019
96b74f6
move tx_handler
Sriep Sep 30, 2019
0e3986c
Merge remote-tracking branch 'remotes/origin/appstate' into debug-evm
Sriep Oct 10, 2019
63368c5
merge master changes
Sriep Oct 10, 2019
91f266f
newMultiWriterVersionReader, unit test
Sriep Oct 14, 2019
9bda227
Merge remote-tracking branch 'remotes/origin/appstate' into debug-evm
Sriep Oct 18, 2019
1c59869
merge-wip
Sriep Oct 21, 2019
fbcfa43
merge-wip
Sriep Oct 21, 2019
7489a31
merge-wip
Sriep Oct 21, 2019
cf0ced2
Add version paramter to GetSnapshot
Sriep Oct 21, 2019
048040c
Modify stores
Sriep Oct 22, 2019
f7682fe
wip
Sriep Oct 22, 2019
d9664f1
merge iAVLVersionReader into iavlStoreSnapshot
Sriep Oct 23, 2019
0053ff4
versionedCachingStore
Sriep Oct 23, 2019
23746d5
PruningIAVLStore
Sriep Oct 23, 2019
c3c0ee4
PruningIAVLStore
Sriep Oct 25, 2019
e7d01f8
PruningIAVLStore
Sriep Oct 30, 2019
cff6ba6
reiview issues store changes
Sriep Oct 30, 2019
f2323ae
use loomchain.Application
Sriep Oct 30, 2019
3f0d006
loomchain.Application
Sriep Oct 30, 2019
39d948d
Add valiadtor functions, fix range
Sriep Oct 31, 2019
5de9514
fx deploy fixes
Sriep Oct 31, 2019
de3313f
fix version number
Sriep Oct 31, 2019
9c3daa1
copy factory, truffle test
Sriep Oct 31, 2019
ba19cf4
revert
Sriep Oct 31, 2019
323fa14
unit test fixes
Sriep Oct 31, 2019
8f3a7ad
unit test fixes
Sriep Nov 1, 2019
ce35dd1
test jenkins
Sriep Nov 1, 2019
5e10bd1
test jenkins
Sriep Nov 1, 2019
882ee71
Merge remote-tracking branch 'remotes/origin/appstate' into debug-evm
Sriep Nov 4, 2019
37838df
merge in master changes
Sriep Nov 4, 2019
66aaf08
makefile
Sriep Nov 4, 2019
48e3738
touch
Sriep Nov 4, 2019
fdfcb2f
Merge remote-tracking branch 'remotes/origin/appstate' into debug-evm
Sriep Nov 4, 2019
4203aaf
touch
Sriep Nov 4, 2019
fff1634
touch
Sriep Nov 4, 2019
3b8d97e
touch
Sriep Nov 4, 2019
9d2b808
touch
Sriep Nov 4, 2019
6d95f13
lint fix
Sriep Nov 4, 2019
6cf49dd
lint fixes
Sriep Nov 4, 2019
4b609de
touch
Sriep Nov 6, 2019
a1d93af
range fix
Sriep Nov 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ BINANCE_TGORACLE_DIR=$(GOPATH)/src/$(PKG_BINANCE_TGORACLE)
# specific commit.
GO_LOOM_GIT_REV = HEAD
# Specifies the loomnetwork/transfer-gateway branch/revision to use.
TG_GIT_REV = HEAD
TG_GIT_REV = config
# loomnetwork/go-ethereum loomchain branch
ETHEREUM_GIT_REV = 1fb6138d017a4309105d91f187c126cf979c93f9
ETHEREUM_GIT_REV = ethapi
# use go-plugin we get 'timeout waiting for connection info' error
HASHICORP_GIT_REV = f4c3476bd38585f9ec669d10ed1686abd52b9961
LEVIGO_GIT_REV = c42d9e0ca023e2198120196f842701bb4c55d7b9
Expand Down
64 changes: 38 additions & 26 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,27 @@ import (
"fmt"
"time"

"github.com/loomnetwork/loomchain/eth/utils"
"github.com/loomnetwork/loomchain/features"
"github.com/loomnetwork/loomchain/registry"

"github.com/go-kit/kit/metrics"
kitprometheus "github.com/go-kit/kit/metrics/prometheus"
cctypes "github.com/loomnetwork/go-loom/builtin/types/chainconfig"
"github.com/pkg/errors"
stdprometheus "github.com/prometheus/client_golang/prometheus"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/common"
ttypes "github.com/tendermint/tendermint/types"

"github.com/loomnetwork/loomchain/eth/utils"
"github.com/loomnetwork/loomchain/features"
"github.com/loomnetwork/loomchain/registry"
"github.com/loomnetwork/loomchain/txhandler"
"github.com/loomnetwork/loomchain/txhandler/middleware"

"github.com/loomnetwork/loomchain/log"
appstate "github.com/loomnetwork/loomchain/state"
"github.com/loomnetwork/loomchain/store"
blockindex "github.com/loomnetwork/loomchain/store/block_index"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
)

type TxHandler interface {
ProcessTx(state appstate.State, txBytes []byte, isCheckTx bool) (TxHandlerResult, error)
}

type TxHandlerFunc func(state appstate.State, txBytes []byte, isCheckTx bool) (TxHandlerResult, error)

type TxHandlerResult struct {
Data []byte
ValidatorUpdates []abci.Validator
Info string
// Tags to associate with the tx that produced this result. Tags can be used to filter txs
// via the ABCI query interface (see https://godoc.org/github.com/tendermint/tendermint/libs/pubsub/query)
Tags []common.KVPair
}

func (f TxHandlerFunc) ProcessTx(state appstate.State, txBytes []byte, isCheckTx bool) (TxHandlerResult, error) {
return f(state, txBytes, isCheckTx)
}

type QueryHandler interface {
Handle(state appstate.ReadOnlyState, path string, data []byte) ([]byte, error)
}
Expand Down Expand Up @@ -72,10 +55,11 @@ type Application struct {
curBlockHash []byte
Store store.VersionedKVStore
Init func(appstate.State) error
TxHandler
txhandler.TxHandler
QueryHandler
EventHandler
ReceiptHandlerProvider
txhandler.TxHandlerFactory
EvmAuxStore *evmaux.EvmAuxStore
blockindex.BlockIndexStore
CreateValidatorManager ValidatorsManagerFactoryFunc
Expand All @@ -88,6 +72,7 @@ type Application struct {
config *cctypes.Config
childTxRefs []evmaux.ChildTxRef // links Tendermint txs to EVM txs
ReceiptsVersion int32
DebugTxHandler txhandler.TxHandler
}

var _ abci.Application = &Application{}
Expand Down Expand Up @@ -437,7 +422,7 @@ func (a *Application) deliverTx(storeTx store.KVStoreTx, txBytes []byte) abci.Re
return abci.ResponseDeliverTx{Code: abci.CodeTypeOK, Data: r.Data, Tags: r.Tags, Info: r.Info}
}

func (a *Application) processTx(storeTx store.KVStoreTx, txBytes []byte, isCheckTx bool) (TxHandlerResult, error) {
func (a *Application) processTx(storeTx store.KVStoreTx, txBytes []byte, isCheckTx bool) (txhandler.TxHandlerResult, error) {
state := appstate.NewStoreState(
context.Background(),
storeTx,
Expand Down Expand Up @@ -621,3 +606,30 @@ func (a *Application) ReadOnlyState() appstate.State {
a.GetValidatorSet,
)
}

func (a *Application) InMemoryApp(blockNumber uint64, blockstore store.BlockStore) (middleware.InMemoryApp, error) {
startVersion := int64(blockNumber) - 1
if startVersion < 0 {
return nil, errors.Errorf("invalid block number %d", blockNumber)
}
for ; !a.Store.VersionExists(startVersion) || startVersion <= int64(0); startVersion-- {
}
if startVersion == 0 {
return nil, errors.Errorf("no saved version for height %d", blockNumber)
}
startStore, err := a.Store.RetrieveVersion(startVersion)
if err != nil {
return nil, err
}

return middleware.NewInMemoryApp(
Sriep marked this conversation as resolved.
Show resolved Hide resolved
startVersion,
blockstore,
startStore,
a.TxHandler,
a.ReceiptsVersion,
a.GetValidatorSet,
a.config,
a.TxHandlerFactory,
), nil
}
61 changes: 24 additions & 37 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (

loom "github.com/loomnetwork/go-loom"
"github.com/loomnetwork/go-loom/util"
"github.com/loomnetwork/loomchain"
"github.com/loomnetwork/loomchain/auth/keys"
"github.com/loomnetwork/loomchain/auth/sequence"
appstate "github.com/loomnetwork/loomchain/state"
"github.com/loomnetwork/loomchain/store"
"github.com/loomnetwork/loomchain/txhandler"
)

var (
Expand All @@ -31,28 +33,13 @@ func init() {
}, []string{})
}

type contextKey string

func (c contextKey) String() string {
return "auth " + string(c)
}

var (
ContextKeyOrigin = contextKey("origin")
ContextKeyCheckTx = contextKey("CheckTx")
)

func Origin(ctx context.Context) loom.Address {
return ctx.Value(ContextKeyOrigin).(loom.Address)
}

var SignatureTxMiddleware = loomchain.TxMiddlewareFunc(func(
var SignatureTxMiddleware = txhandler.TxMiddlewareFunc(func(
state appstate.State,
txBytes []byte,
next loomchain.TxHandlerFunc,
next txhandler.TxHandlerFunc,
isCheckTx bool,
) (loomchain.TxHandlerResult, error) {
var r loomchain.TxHandlerResult
) (txhandler.TxHandlerResult, error) {
var r txhandler.TxHandlerResult

var tx SignedTx
err := proto.Unmarshal(txBytes, &tx)
Expand All @@ -65,7 +52,7 @@ var SignatureTxMiddleware = loomchain.TxMiddlewareFunc(func(
return r, err
}

ctx := context.WithValue(state.Context(), ContextKeyOrigin, origin)
ctx := context.WithValue(state.Context(), keys.ContextKeyOrigin, origin)
return next(state.WithContext(ctx), tx.Inner, isCheckTx)
})

Expand Down Expand Up @@ -93,7 +80,7 @@ func nonceKey(addr loom.Address) []byte {
}

func Nonce(state appstate.ReadOnlyState, addr loom.Address) uint64 {
return loomchain.NewSequence(nonceKey(addr)).Value(state)
return sequence.NewSequence(nonceKey(addr)).Value(state)
}

type NonceHandler struct {
Expand All @@ -109,11 +96,11 @@ func (n *NonceHandler) Nonce(
state appstate.State,
kvStore store.KVStore,
txBytes []byte,
next loomchain.TxHandlerFunc,
next txhandler.TxHandlerFunc,
isCheckTx bool,
) (loomchain.TxHandlerResult, error) {
var r loomchain.TxHandlerResult
origin := Origin(state.Context())
) (txhandler.TxHandlerResult, error) {
var r txhandler.TxHandlerResult
origin := keys.Origin(state.Context())
if origin.IsEmpty() {
return r, errors.New("transaction has no origin [nonce]")
}
Expand All @@ -127,9 +114,9 @@ func (n *NonceHandler) Nonce(
incrementNonceOnFailedTx := state.Config().GetNonceHandler().GetIncNonceOnFailedTx()
if incrementNonceOnFailedTx && !isCheckTx {
// Unconditionally increment the nonce in DeliverTx, regardless of whether the tx succeeds
seq = loomchain.NewSequence(nonceKey(origin)).Next(kvStore)
seq = sequence.NewSequence(nonceKey(origin)).Next(kvStore)
} else {
seq = loomchain.NewSequence(nonceKey(origin)).Next(state)
seq = sequence.NewSequence(nonceKey(origin)).Next(state)
}

var tx NonceTx
Expand Down Expand Up @@ -171,11 +158,11 @@ func (n *NonceHandler) Nonce(
func (n *NonceHandler) IncNonce(
state appstate.State,
txBytes []byte,
result loomchain.TxHandlerResult,
postcommit loomchain.PostCommitHandler,
result txhandler.TxHandlerResult,
postcommit txhandler.PostCommitHandler,
isCheckTx bool,
) error {
origin := Origin(state.Context())
origin := keys.Origin(state.Context())
if origin.IsEmpty() {
return errors.New("transaction has no origin [IncNonce]")
}
Expand All @@ -192,17 +179,17 @@ func (n *NonceHandler) IncNonce(
return nil
}

func (n *NonceHandler) TxMiddleware(kvStore store.KVStore) loomchain.TxMiddlewareFunc {
return loomchain.TxMiddlewareFunc(func(
func (n *NonceHandler) TxMiddleware(kvStore store.KVStore) txhandler.TxMiddlewareFunc {
return txhandler.TxMiddlewareFunc(func(
state appstate.State,
txBytes []byte,
next loomchain.TxHandlerFunc,
next txhandler.TxHandlerFunc,
isCheckTx bool,
) (res loomchain.TxHandlerResult, err error) {
) (res txhandler.TxHandlerResult, err error) {
return n.Nonce(state, kvStore, txBytes, next, isCheckTx)
})
}

func (n *NonceHandler) PostCommitMiddleware() loomchain.PostCommitMiddlewareFunc {
return loomchain.PostCommitMiddlewareFunc(n.IncNonce)
func (n *NonceHandler) PostCommitMiddleware() txhandler.PostCommitMiddlewareFunc {
return txhandler.PostCommitMiddlewareFunc(n.IncNonce)
}
Loading