Skip to content

Commit

Permalink
Merge pull request #257 from CortexFoundation/ucwong
Browse files Browse the repository at this point in the history
Ucwong to Master branch
  • Loading branch information
ucwong authored Nov 28, 2019
2 parents 8789474 + 6f85984 commit e483aff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 4 additions & 0 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type TrustedCheckpoint struct {
SectionHead common.Hash `json:"sectionHead"`
TfsBlocks uint64 `json:"tfsBlocks"`
TfsCheckPoint uint64 `json:"tfsCheckPoint"`
TfsCkpHead common.Hash `json:"tfsCkpHead"`
TfsFiles uint64 `json:"tfsFiles"`
}

var (
Expand All @@ -68,6 +70,8 @@ var (
SectionHead: common.HexToHash("0xbcb220cb151820896fe9ef0138b7d433ded14e9b489def7bfb4819bbf28be95e"),
TfsBlocks: 96,
TfsCheckPoint: 395964,
TfsCkpHead: common.HexToHash("0x155637e09a5c0fc5b4a712abdf032242447f24cd989846fb96afce3927e8257c"),
TfsFiles: 46,
}
//0x78c5f644c046fb0ea544b50a898ca5d2a926c419863853ac8ba22c10fc380fd6
DoloresTrustedCheckpoint = &TrustedCheckpoint{
Expand Down
17 changes: 13 additions & 4 deletions torrentfs/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,17 @@ func (m *Monitor) storageInit() error {
return err
}
if checkpoint, ok := params.TrustedCheckpoints[genesis.Hash]; ok {
if uint64(len(m.fs.Blocks())) < checkpoint.TfsBlocks || uint64(m.fs.CheckPoint) < checkpoint.TfsCheckPoint {
m.lastNumber = 0
log.Info("Torrent fs block dismatch, reloading ...", "blocks", len(m.fs.Blocks()), "limit", checkpoint.TfsBlocks, "ckp", m.fs.CheckPoint, "checkpoint", checkpoint.TfsCheckPoint)
if uint64(len(m.fs.Blocks())) < checkpoint.TfsBlocks || uint64(m.fs.CheckPoint) < checkpoint.TfsCheckPoint || uint64(len(m.fs.Files())) < checkpoint.TfsFiles {
m.lastNumber = m.fs.CheckPoint
log.Info("Torrent fs block unmatch, reloading ...", "blocks", len(m.fs.Blocks()), "limit", checkpoint.TfsBlocks, "ckp", m.fs.CheckPoint, "checkpoint", checkpoint.TfsCheckPoint, "files", len(m.fs.Files()))
} else {
log.Info("Torrent fs block passed", "blocks", len(m.fs.Blocks()), "limit", checkpoint.TfsBlocks, "ckp", m.fs.CheckPoint, "checkpoint", checkpoint.TfsCheckPoint)
block := m.fs.GetBlockByNumber(checkpoint.TfsCheckPoint)
if block != nil && checkpoint.TfsCkpHead == block.Hash {
log.Info("Torrent fs block passed", "blocks", len(m.fs.Blocks()), "limit", checkpoint.TfsBlocks, "ckp", m.fs.CheckPoint, "checkpoint", checkpoint.TfsCheckPoint, "files", len(m.fs.Files()), "head", block.Hash)
} else {
log.Info("Torrent fs check point unmatch, reloading ...", "blocks", len(m.fs.Blocks()), "limit", checkpoint.TfsBlocks, "ckp", m.fs.CheckPoint, "checkpoint", checkpoint.TfsCheckPoint, "files", len(m.fs.Files()), "head", block.Hash)
m.lastNumber = 0
}
}
}

Expand All @@ -202,6 +208,9 @@ func (m *Monitor) storageInit() error {
})

for _, block := range m.fs.Blocks() {
if b, err := m.rpcBlockByNumber(block.Number); err == nil && b.Hash != block.Hash {
m.lastNumber = 0
}
if record, parseErr := m.parseBlockTorrentInfo(block); parseErr != nil {
log.Error("Parse new block", "number", block.Number, "block", block, "error", parseErr)
return parseErr
Expand Down
1 change: 1 addition & 0 deletions torrentfs/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func (fs *FileStorage) Close() error {
//for {
// if fs.opCounter.IsZero() {
// persist storage block number
fs.writeCheckPoint()
log.Info("Torrent File Storage Closed", "database", fs.db.Path())
return fs.writeBlockNumber()
//fs.writeLastFileIndex()
Expand Down

0 comments on commit e483aff

Please sign in to comment.