Skip to content

Commit c38f272

Browse files
committed
replace gob with rlp
1 parent 5adf3da commit c38f272

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

core/genesis.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package core
1818

1919
import (
2020
"bytes"
21-
"encoding/gob"
2221
"encoding/json"
2322
"errors"
2423
"fmt"
@@ -289,14 +288,12 @@ func saveVerkleTransitionStatusAtVerlkeGenesis(db ethdb.Database) {
289288
}
290289

291290
func saveVerkleTransitionStatus(db ethdb.Database, root common.Hash, ts *overlay.TransitionState) {
292-
var buf bytes.Buffer
293-
enc := gob.NewEncoder(&buf)
294-
err := enc.Encode(ts)
291+
enc, err := rlp.EncodeToBytes(ts)
295292
if err != nil {
296293
log.Error("failed to encode transition state", "err", err)
297294
return
298295
}
299-
rawdb.WriteVerkleTransitionState(db, root, buf.Bytes())
296+
rawdb.WriteVerkleTransitionState(db, root, enc)
300297
}
301298

302299
// SetupGenesisBlock writes or updates the genesis block in db.

core/overlay/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import "github.com/ethereum/go-ethereum/common"
2121
// TransitionState is a structure that holds the progress markers of the
2222
// translation process.
2323
type TransitionState struct {
24-
CurrentAccountAddress *common.Address // addresss of the last translated account
24+
CurrentAccountAddress *common.Address `rlp:"nil"` // addresss of the last translated account
2525
CurrentSlotHash common.Hash // hash of the last translated storage slot
2626
CurrentPreimageOffset uint64 // next byte to read from the preimage file
2727
Started, Ended bool

core/state/database.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package state
1818

1919
import (
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

Comments
 (0)