1717package state
1818
1919import (
20- "bytes"
21- "encoding/gob"
2220 "fmt"
2321 "reflect"
2422
@@ -31,6 +29,7 @@ import (
3129 "github.com/ethereum/go-ethereum/crypto"
3230 "github.com/ethereum/go-ethereum/ethdb"
3331 "github.com/ethereum/go-ethereum/log"
32+ "github.com/ethereum/go-ethereum/rlp"
3433 "github.com/ethereum/go-ethereum/trie"
3534 "github.com/ethereum/go-ethereum/trie/trienode"
3635 "github.com/ethereum/go-ethereum/trie/utils"
@@ -300,9 +299,7 @@ func (db *CachingDB) SaveTransitionState(root common.Hash, ts *overlay.Transitio
300299 panic ("nil transition state" )
301300 }
302301
303- var buf bytes.Buffer
304- enc := gob .NewEncoder (& buf )
305- err := enc .Encode (ts )
302+ enc , err := rlp .EncodeToBytes (ts )
306303 if err != nil {
307304 log .Error ("failed to encode transition state" , "err" , err )
308305 return
@@ -312,7 +309,7 @@ func (db *CachingDB) SaveTransitionState(root common.Hash, ts *overlay.Transitio
312309 // Copy so that the address pointer isn't updated after
313310 // it has been saved.
314311 db .TransitionStatePerRoot .Add (root , ts .Copy ())
315- rawdb .WriteVerkleTransitionState (db .TrieDB ().Disk (), root , buf . Bytes () )
312+ rawdb .WriteVerkleTransitionState (db .TrieDB ().Disk (), root , enc )
316313 } else {
317314 // Check that the state is consistent with what is in the cache,
318315 // which is not strictly necessary but a good sanity check. Can
@@ -337,13 +334,10 @@ func (db *CachingDB) LoadTransitionState(root common.Hash) *overlay.TransitionSt
337334
338335 // if a state could be read from the db, attempt to decode it
339336 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+
345339 // Decode transition state
346- err := dec . Decode ( & newts )
340+ err := rlp . DecodeBytes ( data , & newts )
347341 if err != nil {
348342 log .Error ("failed to decode transition state" , "err" , err )
349343 return nil
0 commit comments