Commit 939fbbcf authored by whisker's avatar whisker

fix setConsensusThreshold bug

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