Skip to content

Commit

Permalink
Revert "fix SimulateExecution, add sgd contract check (#3983)"
Browse files Browse the repository at this point in the history
This reverts commit 5df2c68.
  • Loading branch information
dustinxie committed Aug 12, 2024
1 parent 47558dc commit d3ab35a
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
9 changes: 3 additions & 6 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,10 @@ func ExecuteContract(
sharedGasFee.Mul(sharedGasFee, ps.txCtx.GasPrice)
}
totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), ps.txCtx.GasPrice)
if ps.helperCtx.DepositGasFunc != nil {
depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee)
if err != nil {
return nil, nil, err
}
depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee)
if err != nil {
return nil, nil, err
}

}

if err := stateDB.CommitContracts(); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,9 @@ func readExecution(
return nil, nil, err
}
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: getBlockTimeForTest,
GetBlockHash: dao.GetBlockHash,
GetBlockTime: getBlockTimeForTest,
DepositGasFunc: rewarding.DepositGasWithSGD,
})
return sf.SimulateExecution(ctx, addr, exec)
}
Expand Down
9 changes: 0 additions & 9 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ type (
readCache *ReadCache
messageBatcher *batch.Manager
apiStats *nodestats.APILocalStats
sgdIndexer blockindex.SGDRegistry
getBlockTime evm.GetBlockTime
}

Expand Down Expand Up @@ -238,13 +237,6 @@ func WithAPIStats(stats *nodestats.APILocalStats) Option {
}
}

// WithSGDIndexer is the option to return SGD Indexer through API.
func WithSGDIndexer(sgdIndexer blockindex.SGDRegistry) Option {
return func(svr *coreService) {
svr.sgdIndexer = sgdIndexer
}
}

type intrinsicGasCalculator interface {
IntrinsicGas() (uint64, error)
}
Expand Down Expand Up @@ -1913,7 +1905,6 @@ func (core *coreService) simulateExecution(ctx context.Context, addr address.Add
GetBlockHash: getBlockHash,
GetBlockTime: getBlockTime,
DepositGasFunc: rewarding.DepositGasWithSGD,
Sgd: core.sgdIndexer,
})
return core.sf.SimulateExecution(ctx, addr, exec)
}
Expand Down
7 changes: 3 additions & 4 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,12 @@ func (builder *Builder) registerRollDPoSProtocol() error {
return nil, err
}

// TODO: add depositGas
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: getBlockTime,
GetBlockHash: dao.GetBlockHash,
GetBlockTime: getBlockTime,
DepositGasFunc: rewarding.DepositGasWithSGD,
})
data, _, err := factory.SimulateExecution(ctx, addr, ex)

return data, err
},
candidatesutil.CandidatesFromDB,
Expand Down
1 change: 0 additions & 1 deletion chainservice/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func (cs *ChainService) NewAPIServer(cfg api.Config, plugins map[int]interface{}
}),
api.WithNativeElection(cs.electionCommittee),
api.WithAPIStats(cs.apiStats),
api.WithSGDIndexer(cs.sgdIndexer),
}

svr, err := api.NewServerV2(
Expand Down
6 changes: 4 additions & 2 deletions e2etest/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/iotexproject/iotex-core/action/protocol"
"github.com/iotexproject/iotex-core/action/protocol/execution/evm"
"github.com/iotexproject/iotex-core/action/protocol/poll"
"github.com/iotexproject/iotex-core/action/protocol/rewarding"
"github.com/iotexproject/iotex-core/blockchain/genesis"
"github.com/iotexproject/iotex-core/config"
"github.com/iotexproject/iotex-core/pkg/unit"
Expand Down Expand Up @@ -123,8 +124,9 @@ func TestStakingContract(t *testing.T) {
}

ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: fakeGetBlockTime,
GetBlockHash: dao.GetBlockHash,
GetBlockTime: fakeGetBlockTime,
DepositGasFunc: rewarding.DepositGasWithSGD,
})
data, _, err := sf.SimulateExecution(ctx, addr, ex)

Expand Down
1 change: 1 addition & 0 deletions state/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ func testSimulateExecution(ctx context.Context, sf Factory, t *testing.T) {
GetBlockTime: func(u uint64) (time.Time, error) {
return time.Time{}, nil
},
DepositGasFunc: rewarding.DepositGasWithSGD,
})
_, _, err = sf.SimulateExecution(ctx, addr, ex)
require.NoError(err)
Expand Down

0 comments on commit d3ab35a

Please sign in to comment.