Commit ff138022 authored by caopingcp's avatar caopingcp Committed by vipwzw

evm support tx group

parent e7c1e4ab
...@@ -269,6 +269,7 @@ ForkEVMABI=0 ...@@ -269,6 +269,7 @@ ForkEVMABI=0
ForkEVMFrozen=0 ForkEVMFrozen=0
ForkEVMKVHash=0 ForkEVMKVHash=0
ForkEVMYoloV1=0 ForkEVMYoloV1=0
ForkEVMTxGroup=0
[fork.sub.blackwhite] [fork.sub.blackwhite]
Enable=0 Enable=0
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
package executor package executor
import ( import (
"encoding/hex"
"fmt" "fmt"
"strings" "strings"
log "github.com/33cn/chain33/common/log/log15" log "github.com/33cn/chain33/common/log/log15"
...@@ -23,11 +23,12 @@ import ( ...@@ -23,11 +23,12 @@ import (
func (evm *EVMExecutor) Exec(tx *types.Transaction, index int) (*types.Receipt, error) { func (evm *EVMExecutor) Exec(tx *types.Transaction, index int) (*types.Receipt, error) {
evm.CheckInit() evm.CheckInit()
// 先转换消息 // 先转换消息
msg, err := evm.GetMessage(tx) msg, err := evm.GetMessage(tx, index)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return evm.innerExec(msg, tx.Hash(), index, tx.Fee, false)
return evm.innerExec(msg, tx.Hash(), index, evm.GetTxFee(tx, index), false)
} }
// 通用的EVM合约执行逻辑封装 // 通用的EVM合约执行逻辑封装
...@@ -166,7 +167,7 @@ func (evm *EVMExecutor) CheckInit() { ...@@ -166,7 +167,7 @@ func (evm *EVMExecutor) CheckInit() {
} }
// GetMessage 目前的交易中,如果是coins交易,金额是放在payload的,但是合约不行,需要修改Transaction结构 // GetMessage 目前的交易中,如果是coins交易,金额是放在payload的,但是合约不行,需要修改Transaction结构
func (evm *EVMExecutor) GetMessage(tx *types.Transaction) (msg *common.Message, err error) { func (evm *EVMExecutor) GetMessage(tx *types.Transaction, index int) (msg *common.Message, err error) {
var action evmtypes.EVMContractAction var action evmtypes.EVMContractAction
err = types.Decode(tx.Payload, &action) err = types.Decode(tx.Payload, &action)
if err != nil { if err != nil {
...@@ -182,7 +183,7 @@ func (evm *EVMExecutor) GetMessage(tx *types.Transaction) (msg *common.Message, ...@@ -182,7 +183,7 @@ func (evm *EVMExecutor) GetMessage(tx *types.Transaction) (msg *common.Message,
gasLimit := action.GasLimit gasLimit := action.GasLimit
gasPrice := action.GasPrice gasPrice := action.GasPrice
if gasLimit == 0 { if gasLimit == 0 {
gasLimit = uint64(tx.Fee) gasLimit = uint64(evm.GetTxFee(tx, index))
} }
if gasPrice == 0 { if gasPrice == 0 {
gasPrice = uint32(1) gasPrice = uint32(1)
...@@ -224,6 +225,23 @@ func (evm *EVMExecutor) calcKVHash(addr common.Address, logs []*types.ReceiptLog ...@@ -224,6 +225,23 @@ func (evm *EVMExecutor) calcKVHash(addr common.Address, logs []*types.ReceiptLog
return nil return nil
} }
// GetTxFee 获取交易手续费,支持交易组
func (evm *EVMExecutor) GetTxFee(tx *types.Transaction, index int) int64 {
fee := tx.Fee
cfg := evm.GetAPI().GetConfig()
if fee == 0 && cfg.IsDappFork(evm.GetHeight(), "evm", evmtypes.ForkEVMTxGroup) {
if tx.GroupCount >= 2 {
txs, err := evm.GetTxGroup(index)
if err != nil {
log.Error("evm GetTxFee", "get tx group fail", err, "hash", hex.EncodeToString(tx.Hash()))
return 0
}
fee = txs[0].Fee
}
}
return fee
}
func getDataHashKey(addr common.Address) []byte { func getDataHashKey(addr common.Address) []byte {
return []byte(fmt.Sprintf("mavl-%v-data-hash:%v", evmtypes.ExecutorName, addr)) return []byte(fmt.Sprintf("mavl-%v-data-hash:%v", evmtypes.ExecutorName, addr))
} }
......
...@@ -264,7 +264,7 @@ func createContract(mdb *db.GoMemDB, tx types.Transaction, maxCodeSize int) (ret ...@@ -264,7 +264,7 @@ func createContract(mdb *db.GoMemDB, tx types.Transaction, maxCodeSize int) (ret
api, _ := client.New(q.Client(), nil) api, _ := client.New(q.Client(), nil)
inst.SetAPI(api) inst.SetAPI(api)
inst.CheckInit() inst.CheckInit()
msg, _ := inst.GetMessage(&tx) msg, _ := inst.GetMessage(&tx, 0)
inst.SetEnv(10, 0, uint64(10)) inst.SetEnv(10, 0, uint64(10))
statedb = inst.GetMStateDB() statedb = inst.GetMStateDB()
......
...@@ -6,9 +6,8 @@ package types ...@@ -6,9 +6,8 @@ package types
import ( import (
"encoding/json" "encoding/json"
"strings"
"errors" "errors"
"strings"
"github.com/33cn/chain33/common" "github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/address" "github.com/33cn/chain33/common/address"
...@@ -45,6 +44,8 @@ func InitFork(cfg *types.Chain33Config) { ...@@ -45,6 +44,8 @@ func InitFork(cfg *types.Chain33Config) {
cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000) cfg.RegisterDappFork(ExecutorName, ForkEVMFrozen, 1300000)
// EEVM 黄皮v1分叉高度 // EEVM 黄皮v1分叉高度
cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 9500000) cfg.RegisterDappFork(ExecutorName, ForkEVMYoloV1, 9500000)
// EVM合约支持交易组
cfg.RegisterDappFork(ExecutorName, ForkEVMTxGroup, 0)
} }
//InitExecutor ... //InitExecutor ...
......
...@@ -42,6 +42,8 @@ const ( ...@@ -42,6 +42,8 @@ const (
ForkEVMFrozen = "ForkEVMFrozen" ForkEVMFrozen = "ForkEVMFrozen"
// ForkEVMYoloV1 YoloV1虚拟机指令分叉 // ForkEVMYoloV1 YoloV1虚拟机指令分叉
ForkEVMYoloV1 = "ForkEVMYoloV1" ForkEVMYoloV1 = "ForkEVMYoloV1"
//ForkEVMTxGroup 交易组中的交易通过GAS检查
ForkEVMTxGroup = "ForkEVMTxGroup"
) )
var ( var (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment