Skip to content

Commit

Permalink
fix large genesis file commit (#374)
Browse files Browse the repository at this point in the history
* fix large genesis file import
* Update nodedb.go
* changing genesis version check
* fix linter issues

Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
KamiD and robert-zaremba authored May 4, 2021
1 parent 9d0014a commit daefaaf
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions nodedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
)

const (
int64Size = 8
hashSize = sha256.Size
int64Size = 8
hashSize = sha256.Size
genesisVersion = 1
)

var (
Expand Down Expand Up @@ -168,12 +169,31 @@ func (ndb *nodeDB) SaveBranch(node *Node) []byte {
node._hash()
ndb.SaveNode(node)

// resetBatch only working on generate a genesis block
if node.version <= genesisVersion {
ndb.resetBatch()
}
node.leftNode = nil
node.rightNode = nil

return node.hash
}

// resetBatch reset the db batch, keep low memory used
func (ndb *nodeDB) resetBatch() {
var err error
if ndb.opts.Sync {
err = ndb.batch.WriteSync()
} else {
err = ndb.batch.Write()
}
if err != nil {
panic(err)
}
ndb.batch.Close()
ndb.batch = ndb.db.NewBatch()
}

// DeleteVersion deletes a tree version from disk.
func (ndb *nodeDB) DeleteVersion(version int64, checkLatestVersion bool) error {
ndb.mtx.Lock()
Expand Down

0 comments on commit daefaaf

Please sign in to comment.