17
17
package state
18
18
19
19
import (
20
- "bytes"
21
- "encoding/gob"
22
20
"fmt"
23
21
"reflect"
24
22
@@ -31,6 +29,7 @@ import (
31
29
"github.com/ethereum/go-ethereum/crypto"
32
30
"github.com/ethereum/go-ethereum/ethdb"
33
31
"github.com/ethereum/go-ethereum/log"
32
+ "github.com/ethereum/go-ethereum/rlp"
34
33
"github.com/ethereum/go-ethereum/trie"
35
34
"github.com/ethereum/go-ethereum/trie/trienode"
36
35
"github.com/ethereum/go-ethereum/trie/utils"
@@ -300,9 +299,7 @@ func (db *CachingDB) SaveTransitionState(root common.Hash, ts *overlay.Transitio
300
299
panic ("nil transition state" )
301
300
}
302
301
303
- var buf bytes.Buffer
304
- enc := gob .NewEncoder (& buf )
305
- err := enc .Encode (ts )
302
+ enc , err := rlp .EncodeToBytes (ts )
306
303
if err != nil {
307
304
log .Error ("failed to encode transition state" , "err" , err )
308
305
return
@@ -312,7 +309,7 @@ func (db *CachingDB) SaveTransitionState(root common.Hash, ts *overlay.Transitio
312
309
// Copy so that the address pointer isn't updated after
313
310
// it has been saved.
314
311
db .TransitionStatePerRoot .Add (root , ts .Copy ())
315
- rawdb .WriteVerkleTransitionState (db .TrieDB ().Disk (), root , buf . Bytes () )
312
+ rawdb .WriteVerkleTransitionState (db .TrieDB ().Disk (), root , enc )
316
313
} else {
317
314
// Check that the state is consistent with what is in the cache,
318
315
// which is not strictly necessary but a good sanity check. Can
@@ -337,13 +334,10 @@ func (db *CachingDB) LoadTransitionState(root common.Hash) *overlay.TransitionSt
337
334
338
335
// if a state could be read from the db, attempt to decode it
339
336
if len (data ) > 0 {
340
- var (
341
- newts overlay.TransitionState
342
- buf = bytes .NewBuffer (data [:])
343
- dec = gob .NewDecoder (buf )
344
- )
337
+ var newts overlay.TransitionState
338
+
345
339
// Decode transition state
346
- err := dec . Decode ( & newts )
340
+ err := rlp . DecodeBytes ( data , & newts )
347
341
if err != nil {
348
342
log .Error ("failed to decode transition state" , "err" , err )
349
343
return nil
0 commit comments