Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
envestcc committed Nov 9, 2023
1 parent 4d8c37a commit d7bf0a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
41 changes: 23 additions & 18 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ func ExecuteContract(
if err != nil {
return nil, nil, err
}
sgd := ps.helperCtx.Sgd
retval, depositGas, remainingGas, contractAddress, statusCode, err := executeInEVM(ps, stateDB)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -274,23 +273,7 @@ func ExecuteContract(
}
}
if consumedGas > 0 {
var (
receiver address.Address
sharedGas uint64
sharedGasFee, totalGasFee *big.Int
)
if ps.featureCtx.SharedGasWithDapp && sgd != nil {
receiver, sharedGas, err = processSGD(ctx, sm, execution, consumedGas, sgd)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to process Sharing of Gas-fee with DApps")
}
}
if sharedGas > 0 {
sharedGasFee = big.NewInt(int64(sharedGas))
sharedGasFee.Mul(sharedGasFee, ps.txCtx.GasPrice)
}
totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), ps.txCtx.GasPrice)
depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee)
depositLog, err = depositeGas(ctx, sm, execution, consumedGas, ps.txCtx.GasPrice, ps.helperCtx, ps.featureCtx)
if err != nil {
return nil, nil, err
}
Expand All @@ -317,6 +300,27 @@ func ExecuteContract(
return retval, receipt, nil
}

func depositeGas(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, gasPrice *big.Int, hCtx HelperContext, fCtx protocol.FeatureCtx) (*action.TransactionLog, error) {
var (
receiver address.Address
sharedGas uint64
sharedGasFee, totalGasFee *big.Int
err error
)
if fCtx.SharedGasWithDapp && hCtx.Sgd != nil {
receiver, sharedGas, err = processSGD(ctx, sm, execution, consumedGas, hCtx.Sgd)
if err != nil {
return nil, errors.Wrap(err, "failed to process Sharing of Gas-fee with DApps")
}
}
if sharedGas > 0 {
sharedGasFee = big.NewInt(int64(sharedGas))
sharedGasFee.Mul(sharedGasFee, gasPrice)
}
totalGasFee = new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), gasPrice)
return hCtx.DepositGasFunc(ctx, sm, receiver, totalGasFee, sharedGasFee)
}

func processSGD(ctx context.Context, sm protocol.StateManager, execution *action.Execution, consumedGas uint64, sgd SGDRegistry,
) (address.Address, uint64, error) {
if execution.Contract() == action.EmptyAddress {
Expand Down Expand Up @@ -638,6 +642,7 @@ func SimulateExecution(
)

ctx = protocol.WithFeatureCtx(ctx)
// TODO: move the logic out of SimulateExecution
helperCtx := mustGetHelperCtx(ctx)
ctx = WithHelperCtx(ctx, HelperContext{
GetBlockHash: helperCtx.GetBlockHash,
Expand Down
1 change: 1 addition & 0 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ func (core *coreService) Track(ctx context.Context, start time.Time, method stri
}

func (core *coreService) simulateExecution(ctx context.Context, addr address.Address, exec *action.Execution, getBlockHash evm.GetBlockHash) ([]byte, *action.Receipt, error) {
// TODO: add depositGas
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: getBlockHash,
})
Expand Down
1 change: 1 addition & 0 deletions chainservice/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ func (builder *Builder) registerRollDPoSProtocol() error {
return nil, err
}

// TODO: add depositeGas
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
})
Expand Down

0 comments on commit d7bf0a4

Please sign in to comment.