Commit 939fbbcf authored by whisker's avatar whisker

fix setConsensusThreshold bug

parent 2f6c9600
package executor
import (
"errors"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
x2ethereumtypes "github.com/33cn/plugin/plugin/dapp/x2Ethereum/types"
......@@ -18,6 +19,9 @@ import (
// 本端在验证该类型的请求合理后铸币,并生成相同数额的token
func (x *x2ethereum) Exec_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *types.Transaction, index int) (*types.Receipt, error) {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
if payload.ValidatorAddress == "" {
payload.ValidatorAddress = address.PubKeyToAddr(tx.Signature.Pubkey)
}
......@@ -27,6 +31,9 @@ func (x *x2ethereum) Exec_Eth2Chain33(payload *x2ethereumtypes.Eth2Chain33, tx *
// 将因ethereum端锁定的eth或者erc20而在chain33端生成的token返还
func (x *x2ethereum) Exec_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *types.Transaction, index int) (*types.Receipt, error) {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
if payload.ValidatorAddress == "" {
payload.ValidatorAddress = address.PubKeyToAddr(tx.Signature.Pubkey)
}
......@@ -39,6 +46,9 @@ func (x *x2ethereum) Exec_WithdrawEth(payload *x2ethereumtypes.Eth2Chain33, tx *
// WithdrawChain33类型的交易是Chain33侧将本端生成的token返还到Ethereum端
func (x *x2ethereum) Exec_WithdrawChain33(payload *x2ethereumtypes.Chain33ToEth, tx *types.Transaction, index int) (*types.Receipt, error) {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procMsgBurn(payload, defaultCon)
}
......@@ -46,12 +56,18 @@ func (x *x2ethereum) Exec_WithdrawChain33(payload *x2ethereumtypes.Chain33ToEth,
// 在本端锁定一定数额的token,然后在ethereum端生成相同数额的token
func (x *x2ethereum) Exec_Chain33ToEth(payload *x2ethereumtypes.Chain33ToEth, tx *types.Transaction, index int) (*types.Receipt, error) {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procMsgLock(payload, defaultCon)
}
// 转账功能
func (x *x2ethereum) Exec_Transfer(payload *types.AssetsTransfer, tx *types.Transaction, index int) (*types.Receipt, error) {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procMsgTransfer(payload, defaultCon)
}
......@@ -62,6 +78,9 @@ func (x *x2ethereum) Exec_AddValidator(payload *x2ethereumtypes.MsgValidator, tx
err := checkTxSignBySpecificAddr(tx, x2ethereumtypes.X2ethereumAdmin)
if err == nil {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procAddValidator(payload, defaultCon)
}
return nil, err
......@@ -72,6 +91,9 @@ func (x *x2ethereum) Exec_RemoveValidator(payload *x2ethereumtypes.MsgValidator,
err := checkTxSignBySpecificAddr(tx, x2ethereumtypes.X2ethereumAdmin)
if err == nil {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procRemoveValidator(payload, defaultCon)
}
return nil, err
......@@ -82,6 +104,9 @@ func (x *x2ethereum) Exec_ModifyPower(payload *x2ethereumtypes.MsgValidator, tx
err := checkTxSignBySpecificAddr(tx, x2ethereumtypes.X2ethereumAdmin)
if err == nil {
action, defaultCon := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procModifyValidator(payload, defaultCon)
}
return nil, err
......@@ -92,6 +117,9 @@ func (x *x2ethereum) Exec_SetConsensusThreshold(payload *x2ethereumtypes.MsgCons
err := checkTxSignBySpecificAddr(tx, x2ethereumtypes.X2ethereumAdmin)
if err == nil {
action, _ := newAction(x, tx, int32(index))
if action == nil {
return nil, errors.New("Create Action Error")
}
return action.procMsgSetConsensusThreshold(payload)
}
return nil, err
......
......@@ -21,11 +21,11 @@ type Keeper struct {
ConsensusThreshold int64
}
func NewKeeper(db dbm.KV, ConsensusThreshold int64) Keeper {
if ConsensusThreshold <= 0 || ConsensusThreshold > 1 {
panic(types.ErrMinimumConsensusNeededInvalid)
func NewKeeper(db dbm.KV, ConsensusThreshold int64) *Keeper {
if ConsensusThreshold <= 0 || ConsensusThreshold > 100 {
return nil
}
return Keeper{
return &Keeper{
db: db,
ConsensusThreshold: ConsensusThreshold,
}
......
......@@ -86,10 +86,13 @@ func newAction(a *x2ethereum, tx *chain33types.Transaction, index int32) (*actio
ConsensusThreshold = mc.NowConsensusThreshold
}
oracleKeeper := oracle.NewKeeper(a.GetStateDB(), ConsensusThreshold)
if oracleKeeper == nil {
return nil, true
}
elog.Info("newAction", "newAction", "done")
return &action{a.GetAPI(), a.GetCoinsAccount(), a.GetStateDB(), hash, fromaddr,
a.GetBlockTime(), a.GetHeight(), index, address.ExecAddress(string(tx.Execer)), ethbridge.NewKeeper(&oracleKeeper, a.GetStateDB())}, defaultCon
a.GetBlockTime(), a.GetHeight(), index, address.ExecAddress(string(tx.Execer)), ethbridge.NewKeeper(oracleKeeper, a.GetStateDB())}, defaultCon
}
// ethereum ---> chain33
......@@ -189,19 +192,19 @@ func (a *action) procMsgEth2Chain33(ethBridgeClaim *types2.Eth2Chain33, defaultC
execlog := &chain33types.ReceiptLog{Ty: types2.TyEth2Chain33Log, Log: chain33types.Encode(&types2.ReceiptEth2Chain33{
EthereumChainID: msgEthBridgeClaim.EthereumChainID,
BridgeContractAddress: msgEthBridgeClaim.BridgeContractAddress,
Nonce: msgEthBridgeClaim.Nonce,
LocalCoinSymbol: msgEthBridgeClaim.LocalCoinSymbol,
LocalCoinExec: msgEthBridgeClaim.LocalCoinExec,
TokenContractAddress: msgEthBridgeClaim.TokenContractAddress,
EthereumSender: msgEthBridgeClaim.EthereumSender,
Chain33Receiver: msgEthBridgeClaim.Chain33Receiver,
ValidatorAddress: msgEthBridgeClaim.ValidatorAddress,
Amount: msgEthBridgeClaim.Amount,
ClaimType: msgEthBridgeClaim.ClaimType,
XTxHash: a.txhash,
XHeight: uint64(a.height),
ProphecyID: ID,
Decimals: msgEthBridgeClaim.Decimals,
Nonce: msgEthBridgeClaim.Nonce,
LocalCoinSymbol: msgEthBridgeClaim.LocalCoinSymbol,
LocalCoinExec: msgEthBridgeClaim.LocalCoinExec,
TokenContractAddress: msgEthBridgeClaim.TokenContractAddress,
EthereumSender: msgEthBridgeClaim.EthereumSender,
Chain33Receiver: msgEthBridgeClaim.Chain33Receiver,
ValidatorAddress: msgEthBridgeClaim.ValidatorAddress,
Amount: msgEthBridgeClaim.Amount,
ClaimType: msgEthBridgeClaim.ClaimType,
XTxHash: a.txhash,
XHeight: uint64(a.height),
ProphecyID: ID,
Decimals: msgEthBridgeClaim.Decimals,
})}
receipt.Logs = append(receipt.Logs, execlog)
......@@ -401,19 +404,19 @@ func (a *action) procWithdrawEth(withdrawEth *types2.Eth2Chain33, defaultCon boo
execlog := &chain33types.ReceiptLog{Ty: types2.TyWithdrawEthLog, Log: chain33types.Encode(&types2.ReceiptEth2Chain33{
EthereumChainID: msgWithdrawEth.EthereumChainID,
BridgeContractAddress: msgWithdrawEth.BridgeContractAddress,
Nonce: msgWithdrawEth.Nonce,
LocalCoinSymbol: msgWithdrawEth.LocalCoinSymbol,
LocalCoinExec: msgWithdrawEth.LocalCoinExec,
TokenContractAddress: msgWithdrawEth.TokenContractAddress,
EthereumSender: msgWithdrawEth.EthereumSender,
Chain33Receiver: msgWithdrawEth.Chain33Receiver,
ValidatorAddress: msgWithdrawEth.ValidatorAddress,
Amount: msgWithdrawEth.Amount,
ClaimType: msgWithdrawEth.ClaimType,
XTxHash: a.txhash,
XHeight: uint64(a.height),
ProphecyID: ID,
Decimals: msgWithdrawEth.Decimals,
Nonce: msgWithdrawEth.Nonce,
LocalCoinSymbol: msgWithdrawEth.LocalCoinSymbol,
LocalCoinExec: msgWithdrawEth.LocalCoinExec,
TokenContractAddress: msgWithdrawEth.TokenContractAddress,
EthereumSender: msgWithdrawEth.EthereumSender,
Chain33Receiver: msgWithdrawEth.Chain33Receiver,
ValidatorAddress: msgWithdrawEth.ValidatorAddress,
Amount: msgWithdrawEth.Amount,
ClaimType: msgWithdrawEth.ClaimType,
XTxHash: a.txhash,
XHeight: uint64(a.height),
ProphecyID: ID,
Decimals: msgWithdrawEth.Decimals,
})}
receipt.Logs = append(receipt.Logs, execlog)
......@@ -582,8 +585,8 @@ func (a *action) procMsgSetConsensusThreshold(msgSetConsensusThreshold *types2.M
}
setConsensusThreshold := &types2.ReceiptSetConsensusThreshold{
PreConsensusThreshold: int64(preConsensusNeeded * 100),
NowConsensusThreshold: int64(nowConsensusNeeded * 100),
PreConsensusThreshold: preConsensusNeeded,
NowConsensusThreshold: nowConsensusNeeded,
XTxHash: a.txhash,
XHeight: uint64(a.height),
}
......
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