Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

fix handler csdb usage, fixes consensus error again #516

Merged
merged 4 commits into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 tests/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ func TestEth_EstimateGas(t *testing.T) {
err := json.Unmarshal(rpcRes.Result, &gas)
require.NoError(t, err, string(rpcRes.Result))

require.Equal(t, "0xf76c", gas)
require.Equal(t, "0xef7e", gas)
}

func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
Expand All @@ -777,7 +777,7 @@ func TestEth_EstimateGas_ContractDeployment(t *testing.T) {
err := json.Unmarshal(rpcRes.Result, &gas)
require.NoError(t, err, string(rpcRes.Result))

require.Equal(t, "0x1cab2", gas.String())
require.Equal(t, "0x1c2c4", gas.String())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, we def need to fix this

}

func TestEth_ExportAccount(t *testing.T) {
Expand Down
38 changes: 23 additions & 15 deletions x/evm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s

// Prepare db for logs
// TODO: block hash
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
if !st.Simulate {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the txCount is used in the stateDB, and since a simulated tx is run only on the node it's submitted to, then this will cause the txCount/stateDB of the node that ran the simulated tx to be different than the other nodes, causing the consensus error

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh great catch! I can we document this on the comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I'll open a follow up with comments!

k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
}

config, found := k.GetChainConfig(ctx)
if !found {
Expand All @@ -75,13 +77,15 @@ func handleMsgEthereumTx(ctx sdk.Context, k Keeper, msg types.MsgEthereumTx) (*s
return nil, err
}

// update block bloom filter
k.Bloom.Or(k.Bloom, executionResult.Bloom)
if !st.Simulate {
// update block bloom filter
k.Bloom.Or(k.Bloom, executionResult.Bloom)

// update transaction logs in KVStore
err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs)
if err != nil {
panic(err)
// update transaction logs in KVStore
err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs)
if err != nil {
panic(err)
}
}

// log successful execution
Expand Down Expand Up @@ -143,8 +147,10 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
}

// Prepare db for logs
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
if !st.Simulate {
k.CommitStateDB.Prepare(ethHash, common.Hash{}, k.TxCount)
k.TxCount++
}

config, found := k.GetChainConfig(ctx)
if !found {
Expand All @@ -157,12 +163,14 @@ func handleMsgEthermint(ctx sdk.Context, k Keeper, msg types.MsgEthermint) (*sdk
}

// update block bloom filter
k.Bloom.Or(k.Bloom, executionResult.Bloom)
if !st.Simulate {
k.Bloom.Or(k.Bloom, executionResult.Bloom)

// update transaction logs in KVStore
err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs)
if err != nil {
panic(err)
// update transaction logs in KVStore
err = k.SetLogs(ctx, common.BytesToHash(txHash), executionResult.Logs)
if err != nil {
panic(err)
}
}

// log successful execution
Expand Down