Commit 325ff9c1 authored by linj's avatar linj Committed by 33cn

use proto.Clone for copy

parent 40abf871
......@@ -15,6 +15,7 @@ import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
)
......@@ -431,12 +432,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
receipt = makeCommitReceipt(a.fromaddr, commit, nil, stat)
} else {
var copyStat pt.ParacrossHeightStatus
err = deepCopy(&copyStat, stat)
if err != nil {
clog.Error("paracross.Commit deep copy fail", "copy", copyStat, "stat", stat)
return nil, err
}
copyStat := proto.Clone(stat).(*pt.ParacrossHeightStatus)
// 如有分叉, 同一个节点可能再次提交commit交易
found, index := hasCommited(stat.Details.Addrs, a.fromaddr)
if found {
......@@ -452,7 +448,7 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
}
}
receipt = makeCommitReceipt(a.fromaddr, commit, &copyStat, stat)
receipt = makeCommitReceipt(a.fromaddr, commit, copyStat, stat)
}
//平行链fork pt.ForkCommitTx=0,主链在ForkCommitTx后支持nodegroup,这里平行链dappFork一定为true
if cfg.IsDappFork(commit.Status.MainBlockHeight, pt.ParaX, pt.ForkCommitTx) {
......
......@@ -7,6 +7,7 @@ package executor
import (
"github.com/33cn/chain33/common"
dbm "github.com/33cn/chain33/common/db"
"github.com/golang/protobuf/proto"
"sort"
......@@ -125,14 +126,9 @@ func updateStages(db dbm.KV, stage *pt.SelfConsensStage) (*types.Receipt, error)
return makeStageGroupReceipt(nil, stages), nil
}
var old pt.SelfConsensStages
err = deepCopy(&old, stages)
if err != nil {
clog.Error("updateStages deep copy fail", "copy", old, "stat", stages)
return nil, err
}
old := proto.Clone(stages).(*pt.SelfConsensStages)
sortStages(stages, stage)
return makeStageGroupReceipt(&old, stages), nil
return makeStageGroupReceipt(old, stages), nil
}
......@@ -230,16 +226,10 @@ func (a *action) stageCancel(config *pt.ConfigCancelInfo) (*types.Receipt, error
return nil, errors.Wrapf(pt.ErrParaNodeOpStatusWrong, "stage config id:%s,status:%d", config.Id, stat.Status)
}
var copyStat pt.SelfConsensStageInfo
err = deepCopy(&copyStat, stat)
if err != nil {
clog.Error("selfConsensQuit deep copy fail", "copy", copyStat, "stat", stat)
return nil, err
}
copyStat := proto.Clone(stat).(*pt.SelfConsensStageInfo)
stat.Status = pt.ParaApplyCanceled
stat.ExecHeight = a.height
return makeStageConfigReceipt(&copyStat, stat), nil
return makeStageConfigReceipt(copyStat, stat), nil
}
func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
......@@ -266,12 +256,8 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
return nil, err
}
var copyStat pt.SelfConsensStageInfo
err = deepCopy(&copyStat, stat)
if err != nil {
clog.Error("selfConsensVote deep copy fail", "copy", copyStat, "stat", stat)
return nil, err
}
copyStat := proto.Clone(stat).(*pt.SelfConsensStageInfo)
stat.Status = pt.ParaApplyVoting
if stat.Votes == nil {
stat.Votes = &pt.ParaNodeVoteDetail{}
......@@ -289,7 +275,7 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
most, vote := getMostVote(stat.Votes)
if !isCommitDone(nodes, most) {
return makeStageConfigReceipt(&copyStat, stat), nil
return makeStageConfigReceipt(copyStat, stat), nil
}
clog.Info("paracross.stageVote ----pass", "most", most, "pass", vote)
......@@ -303,7 +289,7 @@ func (a *action) stageVote(config *pt.ConfigVoteInfo) (*types.Receipt, error) {
}
stat.Status = pt.ParaApplyClosed
stat.ExecHeight = a.height
r := makeStageConfigReceipt(&copyStat, stat)
r := makeStageConfigReceipt(copyStat, stat)
receipt = mergeReceipt(receipt, r)
r = makeStageVoteDoneReceipt(stat.Stage, len(nodes), len(stat.Votes.Addrs), most, pt.ParaNodeVoteStr[vote])
......
......@@ -5,9 +5,6 @@
package executor
import (
"bytes"
"encoding/gob"
"strings"
"strconv"
......@@ -18,17 +15,10 @@ import (
manager "github.com/33cn/chain33/system/dapp/manage/types"
"github.com/33cn/chain33/types"
pt "github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/golang/protobuf/proto"
"github.com/pkg/errors"
)
func deepCopy(dst, src interface{}) error {
var buf bytes.Buffer
if err := gob.NewEncoder(&buf).Encode(src); err != nil {
return err
}
return gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst)
}
func getNodeAddr(db dbm.KV, title, addr string) (*pt.ParaNodeAddrIdStatus, error) {
key := calcParaNodeAddrKey(title, addr)
val, err := db.Get(key)
......@@ -332,12 +322,7 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
return nil, errors.Wrapf(pt.ErrParaNodeOpStatusWrong, "config id:%s,status:%d", config.Id, stat.Status)
}
var copyStat pt.ParaNodeIdStatus
err = deepCopy(&copyStat, stat)
if err != nil {
clog.Error("nodeaccount.nodeQuit deep copy fail", "copy", copyStat, "stat", stat)
return nil, err
}
copyStat := proto.Clone(stat).(*pt.ParaNodeIdStatus)
if stat.Status == pt.ParaApplyJoining {
receipt := &types.Receipt{Ty: types.ExecOk}
cfg := a.api.GetConfig()
......@@ -350,7 +335,7 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
}
stat.Status = pt.ParaApplyCanceled
stat.Height = a.height
r := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
r := makeNodeConfigReceipt(a.fromaddr, config, copyStat, stat)
receipt = mergeReceipt(receipt, r)
return receipt, nil
}
......@@ -358,7 +343,7 @@ func (a *action) nodeCancel(config *pt.ParaNodeAddrConfig) (*types.Receipt, erro
if stat.Status == pt.ParaApplyQuiting {
stat.Status = pt.ParaApplyCanceled
stat.Height = a.height
return makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat), nil
return makeNodeConfigReceipt(a.fromaddr, config, copyStat, stat), nil
}
return nil, errors.Wrapf(pt.ErrParaUnSupportNodeOper, "nodeid %s was quit status:%d", config.Id, stat.Status)
......@@ -520,13 +505,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
return nil, errors.Wrapf(pt.ErrParaNodeAddrNotExisted, "config id:%s,addr:%s", config.Id, stat.TargetAddr)
}
var copyStat pt.ParaNodeIdStatus
err = deepCopy(&copyStat, stat)
if err != nil {
clog.Error("nodeaccount.nodevOTE deep copy fail", "copy", copyStat, "stat", stat)
return nil, err
}
copyStat := proto.Clone(stat).(*pt.ParaNodeIdStatus)
if stat.Votes == nil {
stat.Votes = &pt.ParaNodeVoteDetail{}
}
......@@ -557,7 +536,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
//超级用户投yes票,共识停止了一定高度就可以通过,防止当前所有授权节点都忘掉私钥场景
if !(superManagerPass && most > 0 && vote == pt.ParaVoteYes) {
return makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat), nil
return makeNodeConfigReceipt(a.fromaddr, config, copyStat, stat), nil
}
}
clog.Info("paracross.nodeVote ----pass", "most", most, "pass", vote)
......@@ -622,7 +601,7 @@ func (a *action) nodeVote(config *pt.ParaNodeAddrConfig) (*types.Receipt, error)
stat.Height = a.height
}
}
r := makeNodeConfigReceipt(a.fromaddr, config, &copyStat, stat)
r := makeNodeConfigReceipt(a.fromaddr, config, copyStat, stat)
receipt = mergeReceipt(receipt, r)
receiptDone := makeVoteDoneReceipt(stat, len(nodes), len(stat.Votes.Addrs), most, pt.ParaNodeVoteStr[vote], stat.Status)
......
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