@@ -24,7 +24,7 @@ func (tx *StateSyncTx) Type() byte {
2424}
2525
2626func (tx * StateSyncTx ) GetChainID () * uint256.Int {
27- panic ( "chainID called from StateSyncTx" )
27+ return nil
2828}
2929
3030func (tx * StateSyncTx ) GetNonce () uint64 {
@@ -65,31 +65,33 @@ func (tx *StateSyncTx) GetTo() *common.Address {
6565
6666func (tx * StateSyncTx ) AsMessage (_ Signer , baseFee * big.Int , rules * chain.Rules ) (* Message , error ) {
6767 if ! rules .IsStateSync {
68- // TODO change to better name when we have a hard fork for this
68+ // TODO: Change to a better name when we have a hard fork for this.
6969 return nil , errors .New ("StateSync typed tx requires StateSync hard fork" )
7070 }
71+
7172 msg := Message {
73+ to : & common.Address {},
74+ from : common.Address {},
7275 nonce : 0 ,
76+ amount : * uint256 .NewInt (0 ),
7377 gasLimit : 0 ,
7478 gasPrice : * uint256 .NewInt (0 ),
75- tipCap : * uint256 .NewInt (0 ),
7679 feeCap : * uint256 .NewInt (0 ),
77- to : tx .GetTo (),
78- amount : * uint256 .NewInt (0 ),
80+ tipCap : * uint256 .NewInt (0 ),
7981 data : []byte {},
8082 accessList : nil ,
8183 checkNonce : false ,
8284 }
85+
8386 if baseFee != nil {
8487 _ = msg .gasPrice .SetFromBig (baseFee )
8588 }
8689
87- msg .from = common.Address {}
8890 return & msg , nil
8991}
9092
9193func (tx * StateSyncTx ) WithSignature (_ Signer , _ []byte ) (Transaction , error ) {
92- return nil , errors .New ("StateSyncTx are not signed" )
94+ return nil , errors .New ("StateSyncTx is not signed" )
9395}
9496
9597func (tx * StateSyncTx ) Hash () common.Hash {
@@ -105,7 +107,7 @@ func (tx *StateSyncTx) Hash() common.Hash {
105107}
106108
107109func (tx * StateSyncTx ) SigningHash (_ * big.Int ) common.Hash {
108- // StateSync txs are never signed, return canonical hash
110+ // StateSync txs are never signed, return canonical hash.
109111 return tx .Hash ()
110112}
111113
@@ -132,24 +134,26 @@ func (tx *StateSyncTx) RawSignatureValues() (*uint256.Int, *uint256.Int, *uint25
132134func (tx * StateSyncTx ) EncodingSize () int {
133135 var b bytes.Buffer
134136 _ = tx .encode (& b )
135- return 1 + b .Len ()
137+ data := make ([]byte , 1 + b .Len ())
138+ return rlp .StringLen (data )
136139}
137140
138- // EncodeRLP writes the inner payload ([]StateSyncData) without the type prefix .
141+ // EncodeRLP implements rlp.Encoder for database storage .
139142func (tx * StateSyncTx ) EncodeRLP (w io.Writer ) error {
140143 if tx == nil {
141144 return errors .New ("nil StateSyncTx" )
142145 }
143146 var buf bytes.Buffer
147+ buf .WriteByte (StateSyncTxType )
144148 if err := tx .encode (& buf ); err != nil {
145149 return err
146150 }
147- _ , err := w .Write (buf .Bytes ())
148- return err
151+ b := newEncodingBuf ()
152+ defer pooledBuf .Put (b )
153+ return rlp .EncodeString (buf .Bytes (), w , b [:])
149154}
150155
151- // DecodeRLP consumes the RLP stream and populates tx.StateSyncData.
152- // The type byte (0x7F) is already stripped by the UnmarshalTransaction path.
156+ // DecodeRLP implements rlp.Decoder.
153157func (tx * StateSyncTx ) DecodeRLP (s * rlp.Stream ) error {
154158 raw , err := s .Raw ()
155159 if err != nil {
@@ -158,11 +162,20 @@ func (tx *StateSyncTx) DecodeRLP(s *rlp.Stream) error {
158162 return tx .decode (raw )
159163}
160164
165+ // MarshalBinary returns the canonical encoding for network transmission.
161166func (tx * StateSyncTx ) MarshalBinary (w io.Writer ) error {
167+ if tx == nil {
168+ return errors .New ("nil StateSyncTx" )
169+ }
162170 if _ , err := w .Write ([]byte {StateSyncTxType }); err != nil {
163171 return err
164172 }
165- return tx .EncodeRLP (w )
173+ var payloadBuf bytes.Buffer
174+ if err := tx .encode (& payloadBuf ); err != nil {
175+ return err
176+ }
177+ _ , err := w .Write (payloadBuf .Bytes ())
178+ return err
166179}
167180
168181func (tx * StateSyncTx ) Sender (_ Signer ) (common.Address , error ) {
@@ -178,7 +191,7 @@ func (tx *StateSyncTx) GetSender() (common.Address, bool) {
178191}
179192
180193func (tx * StateSyncTx ) SetSender (_ common.Address ) {
181- // no-op, StateSyncTx has no sender
194+ // no-op, StateSyncTx has no sender.
182195}
183196
184197func (tx * StateSyncTx ) IsContractDeploy () bool {
@@ -226,7 +239,7 @@ func (tx *StateSyncTx) encode(buf *bytes.Buffer) error {
226239 if tx == nil {
227240 return errors .New ("nil StateSyncTx" )
228241 }
229- // Validate ascending and contiguous IDs as per PIP-74
242+ // Validate ascending and contiguous IDs as per PIP-74.
230243 var prev uint64
231244 for i , d := range tx .StateSyncData {
232245 if d == nil {
@@ -253,7 +266,7 @@ func (tx *StateSyncTx) decode(b []byte) error {
253266 if err := rlp .DecodeBytes (b , & dec ); err != nil {
254267 return err
255268 }
256- // Validate ascending and contiguous IDs as per PIP-74
269+ // Validate ascending and contiguous IDs as per PIP-74.
257270 if len (dec ) > 0 {
258271 prev := dec [0 ].ID
259272 for i := 1 ; i < len (dec ); i ++ {
0 commit comments