@@ -12,6 +12,12 @@ import (
1212type Round uint64
1313type Signature []byte
1414
15+ func (s Signature ) DeepCopy () interface {} {
16+ cpy := make ([]byte , len (s ))
17+ copy (cpy , s )
18+ return s
19+ }
20+
1521// Block Info struct in XDPoS 2.0, used for vote message, etc.
1622type BlockInfo struct {
1723 Hash common.Hash `json:"hash"`
@@ -27,6 +33,20 @@ type Vote struct {
2733 GapNumber uint64 `json:"gapNumber"`
2834}
2935
36+ func (v * Vote ) DeepCopy () interface {} {
37+ proposedBlockInfoCopy := & BlockInfo {
38+ Hash : v .ProposedBlockInfo .Hash ,
39+ Round : v .ProposedBlockInfo .Round ,
40+ Number : new (big.Int ).Set (v .ProposedBlockInfo .Number ),
41+ }
42+ return & Vote {
43+ signer : v .signer ,
44+ ProposedBlockInfo : proposedBlockInfoCopy ,
45+ Signature : v .Signature .DeepCopy ().(Signature ),
46+ GapNumber : v .GapNumber ,
47+ }
48+ }
49+
3050func (v * Vote ) Hash () common.Hash {
3151 return rlpHash (v )
3252}
@@ -52,6 +72,15 @@ type Timeout struct {
5272 GapNumber uint64
5373}
5474
75+ func (t * Timeout ) DeepCopy () interface {} {
76+ return & Timeout {
77+ signer : t .signer ,
78+ Round : t .Round ,
79+ Signature : t .Signature .DeepCopy ().(Signature ),
80+ GapNumber : t .GapNumber ,
81+ }
82+ }
83+
5584func (t * Timeout ) Hash () common.Hash {
5685 return rlpHash (t )
5786}
@@ -75,6 +104,42 @@ type SyncInfo struct {
75104 HighestTimeoutCert * TimeoutCert
76105}
77106
107+ func (s * SyncInfo ) DeepCopy () interface {} {
108+ var highestQCCopy * QuorumCert
109+ if s .HighestQuorumCert != nil {
110+ sigsCopy := make ([]Signature , len (s .HighestQuorumCert .Signatures ))
111+ for i , sig := range s .HighestQuorumCert .Signatures {
112+ sigsCopy [i ] = sig .DeepCopy ().(Signature )
113+ }
114+ highestQCCopy = & QuorumCert {
115+ ProposedBlockInfo : & BlockInfo {
116+ Hash : s .HighestQuorumCert .ProposedBlockInfo .Hash ,
117+ Round : s .HighestQuorumCert .ProposedBlockInfo .Round ,
118+ Number : new (big.Int ).Set (s .HighestQuorumCert .ProposedBlockInfo .Number ),
119+ },
120+ Signatures : sigsCopy ,
121+ GapNumber : s .HighestQuorumCert .GapNumber ,
122+ }
123+ }
124+
125+ var highestTimeoutCopy * TimeoutCert
126+ if s .HighestTimeoutCert != nil {
127+ sigsCopy := make ([]Signature , len (s .HighestTimeoutCert .Signatures ))
128+ for i , sig := range s .HighestTimeoutCert .Signatures {
129+ sigsCopy [i ] = sig .DeepCopy ().(Signature )
130+ }
131+ highestTimeoutCopy = & TimeoutCert {
132+ Round : s .HighestTimeoutCert .Round ,
133+ Signatures : sigsCopy ,
134+ GapNumber : s .HighestTimeoutCert .GapNumber ,
135+ }
136+ }
137+ return & SyncInfo {
138+ HighestQuorumCert : highestQCCopy ,
139+ HighestTimeoutCert : highestTimeoutCopy ,
140+ }
141+ }
142+
78143func (s * SyncInfo ) Hash () common.Hash {
79144 return rlpHash (s )
80145}
0 commit comments