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

Revert "[iip-15] Sharing gas-fee for DApps (#3844)" (#4361) #4361

Merged
merged 2 commits into from
Aug 13, 2024
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
2 changes: 0 additions & 2 deletions action/protocol/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ type (
FixContractStakingWeightedVotes bool
ExecutionSizeLimit32KB bool
UseZeroNonceForFreshAccount bool
SharedGasWithDapp bool
CandidateRegisterMustWithStake bool
DisableDelegateEndorsement bool
RefactorFreshAccountConversion bool
Expand Down Expand Up @@ -267,7 +266,6 @@ func WithFeatureCtx(ctx context.Context) context.Context {
FixContractStakingWeightedVotes: g.IsRedsea(height),
ExecutionSizeLimit32KB: !g.IsSumatra(height),
UseZeroNonceForFreshAccount: g.IsSumatra(height),
SharedGasWithDapp: g.IsToBeEnabled(height),
CandidateRegisterMustWithStake: !g.IsTsunami(height),
DisableDelegateEndorsement: !g.IsTsunami(height),
RefactorFreshAccountConversion: g.IsTsunami(height),
Expand Down
4 changes: 1 addition & 3 deletions action/protocol/execution/evm/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ type (
HelperContext struct {
GetBlockHash GetBlockHash
GetBlockTime GetBlockTime
DepositGasFunc DepositGasWithSGD
// TODO: sgd should be moved into depositGasFunc
Sgd SGDRegistry
DepositGasFunc DepositGas
}
)

Expand Down
49 changes: 4 additions & 45 deletions action/protocol/execution/evm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@
// GetBlockTime gets block time by height
GetBlockTime func(uint64) (time.Time, error)

// DepositGasWithSGD deposits gas with Sharing of Gas-fee with DApps
DepositGasWithSGD func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error)

// SGDRegistry is the interface for handling Sharing of Gas-fee with DApps
SGDRegistry interface {
CheckContract(context.Context, string) (address.Address, uint64, bool, error)
}
// DepositGas deposits gas
DepositGas func(context.Context, protocol.StateManager, *big.Int) (*action.TransactionLog, error)
)

// CanTransfer checks whether the from account has enough balance
Expand Down Expand Up @@ -240,7 +235,6 @@
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 @@ -275,24 +269,8 @@
}
}
if consumedGas > 0 {
var (
receiver address.Address
sharedGas uint64
sharedGasFee, totalGasFee *big.Int
)
if ps.featureCtx.SharedGasWithDapp && sgd != nil {
// TODO: sgd is whether nil should be checked in processSGD
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)
gasValue := new(big.Int).Mul(new(big.Int).SetUint64(consumedGas), ps.txCtx.GasPrice)
depositLog, err = ps.helperCtx.DepositGasFunc(ctx, sm, gasValue)

Check warning on line 273 in action/protocol/execution/evm/evm.go

View check run for this annotation

Codecov / codecov/patch

action/protocol/execution/evm/evm.go#L272-L273

Added lines #L272 - L273 were not covered by tests
if err != nil {
return nil, nil, err
}
Expand All @@ -319,25 +297,6 @@
return retval, receipt, nil
}

func processSGD(ctx context.Context, sm protocol.StateManager, execution *action.EvmTransaction, consumedGas uint64, sgd SGDRegistry,
) (address.Address, uint64, error) {
if execution.To() == nil {
return nil, 0, nil
}

contract, _ := address.FromBytes((*execution.To())[:])
receiver, percentage, ok, err := sgd.CheckContract(ctx, contract.String())
if err != nil || !ok {
return nil, 0, err
}

sharedGas := consumedGas * percentage / 100
if sharedGas > consumedGas {
sharedGas = consumedGas
}
return receiver, sharedGas, nil
}

// ReadContractStorage reads contract's storage
func ReadContractStorage(
ctx context.Context,
Expand Down
4 changes: 1 addition & 3 deletions action/protocol/execution/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/stretchr/testify/require"

"github.com/iotexproject/go-pkgs/hash"
"github.com/iotexproject/iotex-address/address"
"github.com/iotexproject/iotex-proto/golang/iotextypes"

"github.com/iotexproject/iotex-core/action"
Expand Down Expand Up @@ -67,10 +66,9 @@ func TestExecuteContractFailure(t *testing.T) {
GetBlockTime: func(uint64) (time.Time, error) {
return time.Time{}, nil
},
DepositGasFunc: func(context.Context, protocol.StateManager, address.Address, *big.Int, *big.Int) (*action.TransactionLog, error) {
DepositGasFunc: func(context.Context, protocol.StateManager, *big.Int) (*action.TransactionLog, error) {
return nil, nil
},
Sgd: nil,
})
retval, receipt, err := ExecuteContract(ctx, sm, action.NewEvmTx(e))
require.Nil(t, retval)
Expand Down
8 changes: 3 additions & 5 deletions action/protocol/execution/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,18 @@ const (
type Protocol struct {
getBlockHash evm.GetBlockHash
getBlockTime evm.GetBlockTime
depositGas evm.DepositGasWithSGD
depositGas evm.DepositGas
addr address.Address
sgdRegistry evm.SGDRegistry
}

// NewProtocol instantiates the protocol of exeuction
func NewProtocol(getBlockHash evm.GetBlockHash, depositGasWithSGD evm.DepositGasWithSGD, sgd evm.SGDRegistry, getBlockTime evm.GetBlockTime) *Protocol {
func NewProtocol(getBlockHash evm.GetBlockHash, depositGas evm.DepositGas, getBlockTime evm.GetBlockTime) *Protocol {
h := hash.Hash160b([]byte(_protocolID))
addr, err := address.FromBytes(h[:])
if err != nil {
log.L().Panic("Error when constructing the address of vote protocol", zap.Error(err))
}
return &Protocol{getBlockHash: getBlockHash, depositGas: depositGasWithSGD, addr: addr, sgdRegistry: sgd, getBlockTime: getBlockTime}
return &Protocol{getBlockHash: getBlockHash, depositGas: depositGas, addr: addr, getBlockTime: getBlockTime}
}

// FindProtocol finds the registered protocol from registry
Expand Down Expand Up @@ -72,7 +71,6 @@ func (p *Protocol) Handle(ctx context.Context, act action.Action, sm protocol.St
GetBlockHash: p.getBlockHash,
GetBlockTime: p.getBlockTime,
DepositGasFunc: p.depositGas,
Sgd: p.sgdRegistry,
})
_, receipt, err := evm.ExecuteContract(ctx, sm, action.NewEvmTx(exec))

Expand Down
11 changes: 4 additions & 7 deletions action/protocol/execution/protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func readExecution(
ctx = evm.WithHelperCtx(ctx, evm.HelperContext{
GetBlockHash: dao.GetBlockHash,
GetBlockTime: getBlockTimeForTest,
DepositGasFunc: rewarding.DepositGasWithSGD,
DepositGasFunc: rewarding.DepositGas,
})
return sf.SimulateExecution(ctx, addr, exec)
}
Expand Down Expand Up @@ -492,7 +492,7 @@ func (sct *SmartContractTest) prepareBlockchain(
r.NoError(reward.Register(registry))

r.NotNil(bc)
execution := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
execution := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, getBlockTimeForTest)
r.NoError(execution.Register(registry))
r.NoError(bc.Start(ctx))

Expand Down Expand Up @@ -642,7 +642,7 @@ func TestProtocol_Validate(t *testing.T) {
require := require.New(t)
p := execution.NewProtocol(func(uint64) (hash.Hash256, error) {
return hash.ZeroHash256, nil
}, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
}, rewarding.DepositGas, getBlockTimeForTest)

cases := []struct {
name string
Expand Down Expand Up @@ -735,7 +735,7 @@ func TestProtocol_Handle(t *testing.T) {
protocol.NewGenericValidator(sf, accountutil.AccountState),
)),
)
exeProtocol := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGasWithSGD, nil, getBlockTimeForTest)
exeProtocol := execution.NewProtocol(dao.GetBlockHash, rewarding.DepositGas, getBlockTimeForTest)
require.NoError(exeProtocol.Register(registry))
require.NoError(bc.Start(ctx))
require.NotNil(bc)
Expand Down Expand Up @@ -1145,9 +1145,6 @@ func TestIstanbulEVM(t *testing.T) {
// staticcall -> staticcall -> revrt twice
NewSmartContractTest(t, "testdata-istanbul/write-protection-010.json")
})
t.Run("iip15-manager test", func(t *testing.T) {
NewSmartContractTest(t, "testdata-istanbul/iip15-manager.json")
})
}

func TestLondonEVM(t *testing.T) {
Expand Down
Loading
Loading