Skip to content

Commit

Permalink
Added prioritised handling of submitter contract
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Boben committed Jan 23, 2024
1 parent 44079ee commit b710862
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
29 changes: 29 additions & 0 deletions coreth/core/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ func GetPrioritisedFTSOContract(blockTime *big.Int) string {
}
}

func GetPrioritisedSubmitterContract(blockTime *big.Int) string {
switch {
default:
return "0xEC1C93A9f6a9e18E97784c76aC52053587FcDB89"
}
}

func IsPrioritisedContractCall(to *common.Address, ret []byte, blockTime *big.Int) bool {
switch {
case to == nil:
return false
case *to == common.HexToAddress(GetPrioritisedFTSOContract(blockTime)):
return true
case *to == common.HexToAddress(GetPrioritisedSubmitterContract(blockTime)):
return !isZeroSlice(ret)
default:
return false
}
}

func GetMaximumMintRequest(blockTime *big.Int) *big.Int {
switch {
default:
Expand Down Expand Up @@ -157,3 +177,12 @@ func atomicDaemonAndMint(evm EVMCaller, log log.Logger) {
log.Warn("Daemon error", "error", daemonErr)
}
}

func isZeroSlice(s []byte) bool {
for i := len(s) - 1; i >= 0; i-- {
if s[i] != 0 {
return false
}
}
return true
}
23 changes: 13 additions & 10 deletions coreth/core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ The state transitioning model does all the necessary work to work out a valid ne
3) Create a new state object if the recipient is \0*32
4) Value transfer
== If contract creation ==
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object
== end ==
5) Run Script section
6) Derive new state root
Expand Down Expand Up @@ -300,13 +302,13 @@ func (st *StateTransition) preCheck() error {
// TransitionDb will transition the state by applying the current message and
// returning the evm execution result with following fields.
//
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
// - used gas:
// total gas used (including gas being refunded)
// - returndata:
// the returned data from evm
// - concrete execution error:
// various **EVM** error which aborts the execution,
// e.g. ErrOutOfGas, ErrExecutionReverted
//
// However if any consensus issue encountered, return the error directly with
// nil evm execution result.
Expand Down Expand Up @@ -417,7 +419,8 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
}

st.refundGas(rules.IsApricotPhase1)
if vmerr == nil && msg.To() != nil && *msg.To() == common.HexToAddress(GetPrioritisedFTSOContract(timestamp)) && st.initialGas <= GetMaxFTSOGasLimit(timestamp) {
// if vmerr == nil && msg.To() != nil && *msg.To() == common.HexToAddress(GetPrioritisedFTSOContract(timestamp)) && st.initialGas <= GetMaxFTSOGasLimit(timestamp) {
if vmerr == nil && IsPrioritisedContractCall(msg.To(), ret, timestamp) && st.initialGas <= GetMaxFTSOGasLimit(timestamp) {
nominalGasUsed := uint64(params.TxGas) // 21000
nominalGasPrice := uint64(params.ApricotPhase4MinBaseFee) // 25_000_000_000; the max base fee is 1_000_000_000_000
nominalFee := new(big.Int).Mul(new(big.Int).SetUint64(nominalGasUsed), new(big.Int).SetUint64(nominalGasPrice))
Expand Down

0 comments on commit b710862

Please sign in to comment.