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

Impliments debug_traceTransaction #1573

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
a443c17
debug_traceTransaction
Sriep Nov 7, 2019
d2f2656
external branch changes
Sriep Nov 7, 2019
ba6c0c5
remove comment, noevem
Sriep Nov 7, 2019
b24ae1f
noevem
Sriep Nov 7, 2019
9a17eba
noevem
Sriep Nov 7, 2019
31b9eaf
touch
Sriep Nov 7, 2019
25931d9
tg branch
Sriep Nov 7, 2019
5dad4a2
tg branch
Sriep Nov 7, 2019
621b9ef
unit tests, truffle test
Sriep Nov 7, 2019
7eef46a
unit tests
Sriep Nov 7, 2019
117a17c
try increase sleep
Sriep Nov 7, 2019
df96846
review issues
Sriep Nov 8, 2019
8deefbd
reeview issues,
Sriep Nov 11, 2019
9d4600e
config tracer
Sriep Nov 11, 2019
f49d7c6
truffle test
Sriep Nov 11, 2019
769672f
debug trace
Sriep Nov 11, 2019
895c456
truffle test
Sriep Nov 11, 2019
c556b04
fix vmmanager
Sriep Nov 12, 2019
d9d554c
fix
Sriep Nov 12, 2019
fcc157b
touch
Sriep Nov 12, 2019
cf52a2c
Merge remote-tracking branch 'remotes/origin/master' into ethdebug
Sriep Nov 13, 2019
a970270
touch
Sriep Nov 13, 2019
b1be5c7
test
Sriep Nov 13, 2019
8eee6c4
test
Sriep Nov 13, 2019
548f1d7
test
Sriep Nov 13, 2019
4826258
fix lint errors
Sriep Nov 13, 2019
7bcc26e
untest
Sriep Nov 13, 2019
571c9de
test
Sriep Nov 13, 2019
1a5f57f
noevm
Sriep Nov 13, 2019
8d60e39
debug_storagerangeat
Sriep Nov 14, 2019
66cf306
handle 0x
Sriep Nov 15, 2019
ffb7d75
fix
Sriep Nov 15, 2019
c5874bd
reciew issues
Sriep Nov 18, 2019
cb46125
debug_storageRangeAt
Sriep Nov 18, 2019
971d5cf
Merge remote-tracking branch 'remotes/origin/master' into ethdebug
Sriep Nov 18, 2019
05ddc25
review issues
Sriep Nov 19, 2019
51a8d62
range
Sriep Nov 19, 2019
a9777d0
review issues
Sriep Nov 21, 2019
4a27262
restore
Sriep Nov 21, 2019
bf28c5d
Merge remote-tracking branch 'remotes/origin/master' into ethdebug
Sriep Nov 27, 2019
d73f8e6
sort range
Sriep Nov 27, 2019
d98b4a5
touch
Sriep Nov 27, 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 = debugeth
# 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
147 changes: 110 additions & 37 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/core/vm"
"github.com/loomnetwork/go-loom/config"
"github.com/loomnetwork/go-loom/util"
"github.com/pkg/errors"

"github.com/loomnetwork/loomchain/eth/utils"
"github.com/loomnetwork/loomchain/features"
"github.com/loomnetwork/loomchain/registry"
Expand All @@ -20,14 +23,15 @@ import (
cctypes "github.com/loomnetwork/go-loom/builtin/types/chainconfig"
"github.com/loomnetwork/go-loom/plugin"
"github.com/loomnetwork/go-loom/types"
"github.com/loomnetwork/loomchain/log"
"github.com/loomnetwork/loomchain/store"
blockindex "github.com/loomnetwork/loomchain/store/block_index"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
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/log"
"github.com/loomnetwork/loomchain/store"
blockindex "github.com/loomnetwork/loomchain/store/block_index"
evmaux "github.com/loomnetwork/loomchain/store/evm_aux"
)

type ReadOnlyState interface {
Expand Down Expand Up @@ -302,6 +306,11 @@ type TxHandler interface {
ProcessTx(state State, txBytes []byte, isCheckTx bool) (TxHandlerResult, error)
}

type TxHandlerFactory interface {
TxHandler(tracer vm.Tracer, metrics bool) (TxHandler, error)
Copy(newStore store.VersionedKVStore) TxHandlerFactory
}

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

type TxHandlerResult struct {
Expand Down Expand Up @@ -348,6 +357,7 @@ type Application struct {
Store store.VersionedKVStore
Init func(State) error
TxHandler
TxHandlerFactory
QueryHandler
EventHandler
ReceiptHandlerProvider
Expand Down Expand Up @@ -577,17 +587,19 @@ func (a *Application) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock {
}

// TODO: receiptHandler.CommitBlock() should be moved to Application.Commit()
storeTx := store.WrapAtomic(a.Store).BeginTx()
receiptHandler := a.ReceiptHandlerProvider.Store()
if err := receiptHandler.CommitBlock(a.height()); err != nil {
storeTx.Rollback()
// TODO: maybe panic instead?
log.Error(fmt.Sprintf("aborted committing block receipts, %v", err.Error()))
} else {
storeTx.Commit()
if a.ReceiptHandlerProvider != nil {
storeTx := store.WrapAtomic(a.Store).BeginTx()
receiptHandler := a.ReceiptHandlerProvider.Store()
if err := receiptHandler.CommitBlock(a.height()); err != nil {
storeTx.Rollback()
// TODO: maybe panic instead?
log.Error(fmt.Sprintf("aborted committing block receipts, %v", err.Error()))
} else {
storeTx.Commit()
}
}

storeTx = store.WrapAtomic(a.Store).BeginTx()
storeTx := store.WrapAtomic(a.Store).BeginTx()
state := NewStoreState(
context.Background(),
storeTx,
Expand Down Expand Up @@ -774,15 +786,18 @@ func (a *Application) deliverTx2(storeTx store.KVStoreTx, txBytes []byte) abci.R
a.GetValidatorSet,
).WithOnChainConfig(a.config)

receiptHandler := a.ReceiptHandlerProvider.Store()
defer receiptHandler.DiscardCurrentReceipt()
defer a.EventHandler.Rollback()
if a.ReceiptHandlerProvider != nil {
defer a.ReceiptHandlerProvider.Store().DiscardCurrentReceipt()
}
if a.EventHandler != nil {
defer a.EventHandler.Rollback()
}

r, txErr := a.TxHandler.ProcessTx(state, txBytes, false)

// Store the receipt even if the tx itself failed
var receiptTxHash []byte
if a.ReceiptHandlerProvider.Reader().GetCurrentReceipt() != nil {
if a.ReceiptHandlerProvider != nil && a.ReceiptHandlerProvider.Reader().GetCurrentReceipt() != nil {
receiptTxHash = a.ReceiptHandlerProvider.Reader().GetCurrentReceipt().TxHash
txHash := ttypes.Tx(txBytes).Hash()
// If a receipt was generated for an EVM tx add a link between the TM tx hash and the EVM tx hash
Expand All @@ -793,7 +808,7 @@ func (a *Application) deliverTx2(storeTx store.KVStoreTx, txBytes []byte) abci.R
ChildTxHash: receiptTxHash,
})
}
receiptHandler.CommitCurrentReceipt()
a.ReceiptHandlerProvider.Store().CommitCurrentReceipt()
}

if txErr != nil {
Expand All @@ -804,13 +819,15 @@ func (a *Application) deliverTx2(storeTx store.KVStoreTx, txBytes []byte) abci.R
return abci.ResponseDeliverTx{Code: 1, Data: r.Data, Log: txErr.Error()}
}

a.EventHandler.Commit(uint64(a.curBlockHeader.GetHeight()))
storeTx.Commit()

// FIXME: Really shouldn't be sending out events until the whole block is committed because
// the state changes from the tx won't be visible to queries until after Application.Commit()
if err := a.EventHandler.LegacyEthSubscriptionSet().EmitTxEvent(r.Data, r.Info); err != nil {
log.Error("Emit Tx Event error", "err", err)
if a.EventHandler != nil {
a.EventHandler.Commit(uint64(a.curBlockHeader.GetHeight()))
// FIXME: Really shouldn't be sending out events until the whole block is committed because
// the state changes from the tx won't be visible to queries until after Application.Commit()
if err := a.EventHandler.LegacyEthSubscriptionSet().EmitTxEvent(r.Data, r.Info); err != nil {
log.Error("Emit Tx Event error", "err", err)
}
}

if len(receiptTxHash) > 0 {
Expand All @@ -837,23 +854,28 @@ func (a *Application) Commit() abci.ResponseCommit {

height := a.curBlockHeader.GetHeight()

if err := a.EvmAuxStore.SaveChildTxRefs(a.childTxRefs); err != nil {
// TODO: consider panic instead
log.Error("Failed to save Tendermint -> EVM tx hash refs", "height", height, "err", err)
if a.EvmAuxStore != nil {
if err := a.EvmAuxStore.SaveChildTxRefs(a.childTxRefs); err != nil {
// TODO: consider panic instead
log.Error("Failed to save Tendermint -> EVM tx hash refs", "height", height, "err", err)
}
}
a.childTxRefs = nil

go func(height int64, blockHeader abci.Header) {
if err := a.EventHandler.EmitBlockTx(uint64(height), blockHeader.Time); err != nil {
log.Error("Emit Block Event error", "err", err)
}
if err := a.EventHandler.LegacyEthSubscriptionSet().EmitBlockEvent(blockHeader); err != nil {
log.Error("Emit Block Event error", "err", err)
}
if err := a.EventHandler.EthSubscriptionSet().EmitBlockEvent(blockHeader); err != nil {
log.Error("Emit Block Event error", "err", err)
}
}(height, a.curBlockHeader)
if a.EventHandler != nil {
go func(height int64, blockHeader abci.Header) {
if err := a.EventHandler.EmitBlockTx(uint64(height), blockHeader.Time); err != nil {
log.Error("Emit Block Event error", "err", err)
}
if err := a.EventHandler.LegacyEthSubscriptionSet().EmitBlockEvent(blockHeader); err != nil {
log.Error("Emit Block Event error", "err", err)
}
if err := a.EventHandler.EthSubscriptionSet().EmitBlockEvent(blockHeader); err != nil {
log.Error("Emit Block Event error", "err", err)
}
}(height, a.curBlockHeader)
}

a.lastBlockHeader = a.curBlockHeader

if err := a.Store.Prune(); err != nil {
Expand Down Expand Up @@ -885,6 +907,7 @@ func (a *Application) Query(req abci.RequestQuery) abci.ResponseQuery {
func (a *Application) height() int64 {
return a.Store.Version() + 1
}

func (a *Application) ReadOnlyState() State {
// TODO: the store snapshot should be created atomically, otherwise the block header might
// not match the state... need to figure out why this hasn't spectacularly failed already
Expand All @@ -896,3 +919,53 @@ func (a *Application) ReadOnlyState() State {
a.GetValidatorSet,
)
}

func (a *Application) ReplayApplication(blockNumber uint64, blockstore store.BlockStore) (*Application, int64, error) {
startVersion := int64(blockNumber) - 1
if startVersion < 0 {
return nil, 0, errors.Errorf("invalid block number %d", blockNumber)
}
var snapshot store.Snapshot
for err := error(nil); (snapshot == nil || err != nil) && startVersion > 0; startVersion-- {
snapshot, err = a.Store.GetSnapshotAt(startVersion)
}
if startVersion == 0 {
return nil, 0, errors.Errorf("no saved version for height %d", blockNumber)
}

splitStore := store.NewSplitStore(snapshot, store.NewMemStore(), startVersion-1)
factory := a.TxHandlerFactory.Copy(splitStore)
txHandle, err := factory.TxHandler(nil, false)
if err != nil {
return nil, 0, err
}
newApp := &Application{
Store: splitStore,
Init: func(state State) error {
panic("init should not be called")
},
TxHandler: txHandle,
TxHandlerFactory: factory,
BlockIndexStore: nil,
EventHandler: nil,
ReceiptHandlerProvider: nil,
CreateValidatorManager: a.CreateValidatorManager,
CreateChainConfigManager: a.CreateChainConfigManager,
CreateContractUpkeepHandler: a.CreateContractUpkeepHandler,
EventStore: nil,
GetValidatorSet: a.GetValidatorSet,
EvmAuxStore: nil,
ReceiptsVersion: a.ReceiptsVersion,
config: a.config,
}
return newApp, startVersion, nil
}

func (a *Application) SetTracer(tracer vm.Tracer, metrics bool) error {
newTxHandle, err := a.TxHandlerFactory.TxHandler(tracer, metrics)
if err != nil {
return errors.Wrap(err, "making transaction handle")
}
a.TxHandler = newTxHandle
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func deployContractToEVM(ctx *plugin.FakeContextWithEVM, filename string, caller
byteCode := common.FromHex(string(hexByteCode))
byteCode, err = hex.DecodeString(string(hexByteCode))

vm := evm.NewLoomVm(ctx.State, nil, nil, nil, false)
vm := evm.NewLoomVm(ctx.State, nil, nil, false, nil)
_, contractAddr, err = vm.Create(caller, byteCode, loom.NewBigUIntFromInt(0))
if err != nil {
return contractAddr, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/loom/db/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func newDumpEVMStateCommand() *cobra.Command {
}
}

vm, err := evm.NewLoomEvm(state, accountBalanceManager, nil, false)
vm, err := evm.NewLoomEvm(state, accountBalanceManager, nil, false, nil)
if err != nil {
return err
}
Expand Down Expand Up @@ -221,7 +221,7 @@ func newDumpEVMStateMultiWriterAppStoreCommand() *cobra.Command {
}
}

vm, err := evm.NewLoomEvm(state, accountBalanceManager, nil, false)
vm, err := evm.NewLoomEvm(state, accountBalanceManager, nil, false, nil)
if err != nil {
return err
}
Expand Down
Loading