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

[EVM] Fix timestamp in evm read calls #1486

Merged
merged 5 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ func (app *App) RegisterTendermintService(clientCtx client.Context) {
}
ctx, err := app.CreateQueryContext(i, false)
if err != nil {
app.Logger().Error("failed to create query context for EVM; using latest context instead")
app.Logger().Error(fmt.Sprintf("failed to create query context for EVM; using latest context instead: %v+", err.Error()))
return app.GetCheckCtx()
}
return ctx
Expand Down
27 changes: 22 additions & 5 deletions contracts/test/EVMCompatabilityTester.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,27 @@ describe("EVM Test", function () {


describe("Block Properties", function () {
it("Should get and print the block properties", async function () {
await delay()
const blockProperties = await evmTester.getBlockProperties();
debug(blockProperties)
it("Should have consistent block properties for a block", async function () {
const currentBlockNumber = await ethers.provider.getBlockNumber();
const iface = new ethers.Interface(["function getBlockProperties() view returns (bytes32 blockHash, address coinbase, uint256 prevrandao, uint256 gaslimit, uint256 number, uint256 timestamp)"]);
const addr = await evmTester.getAddress()
const tx = {
to: addr,
data: iface.encodeFunctionData("getBlockProperties", []),
blockTag: currentBlockNumber-2
};
const result = await ethers.provider.call(tx);

// wait for block to change
while(true){
const bn = await ethers.provider.getBlockNumber();
if(bn !== currentBlockNumber){
break
}
await sleep(100)
}
const result2 = await ethers.provider.call(tx);
expect(result).to.equal(result2)
});
});

Expand Down Expand Up @@ -291,7 +308,7 @@ describe("EVM Test", function () {
})

describe("Historical query test", function() {
it.only("Should be able to get historical block data", async function() {
it("Should be able to get historical block data", async function() {
const feeData = await ethers.provider.getFeeData();
const gasPrice = Number(feeData.gasPrice);
const zero = ethers.parseUnits('0', 'ether')
Expand Down
10 changes: 7 additions & 3 deletions evmrpc/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,12 @@ func (b *Backend) StateAtBlock(ctx context.Context, block *ethtypes.Block, reexe
return statedb, emptyRelease, nil
}

func (b *Backend) GetEVM(_ context.Context, msg *core.Message, stateDB vm.StateDB, _ *ethtypes.Header, vmConfig *vm.Config, _ *vm.BlockContext) *vm.EVM {
func (b *Backend) GetEVM(_ context.Context, msg *core.Message, stateDB vm.StateDB, _ *ethtypes.Header, vmConfig *vm.Config, blockCtx *vm.BlockContext) *vm.EVM {
txContext := core.NewEVMTxContext(msg)
context, _ := b.keeper.GetVMBlockContext(b.ctxProvider(LatestCtxHeight), core.GasPool(b.RPCGasCap()))
evm := vm.NewEVM(*context, txContext, stateDB, b.ChainConfig(), *vmConfig)
if blockCtx == nil {
blockCtx, _ = b.keeper.GetVMBlockContext(b.ctxProvider(LatestCtxHeight), core.GasPool(b.RPCGasCap()))
}
evm := vm.NewEVM(*blockCtx, txContext, stateDB, b.ChainConfig(), *vmConfig)
if dbImpl, ok := stateDB.(*state.DBImpl); ok {
dbImpl.SetEVM(evm)
}
Expand Down Expand Up @@ -360,8 +362,10 @@ func (b *Backend) getHeader(blockNumber *big.Int) *ethtypes.Header {
}
number := blockNumber.Int64()
block, err := blockByNumber(context.Background(), b.tmClient, &number)
//TODO: what should happen if an err occurs here?
if err == nil {
header.ParentHash = common.BytesToHash(block.BlockID.Hash)
header.Time = uint64(block.Block.Header.Time.Unix())
}
return header
}
Expand Down
Loading