-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RPCDaemon: don't open uncomplete files at startup (#12332)
Probably right way is: check `StageSnapshots > 0` as "all downloads done". Because: - --prune.mode=minimal has not much files, but `preverified.toml` stays the same - downloader has logic to of prohibit_new_downloads.lock - downloading consider doen't even if `preverified.toml` has more files - small files may get merged - while `preverified.toml` stays the same - developer may generate new version of file (hash or len changed) - while `preverified.toml` stays the same - Downloader's `Complete` flag can't be used - because e3 does download headers and bodies first, then Complete=true happens, and then we download transactions (Complete=false happens).
- Loading branch information
1 parent
ea2ca63
commit 200c85b
Showing
12 changed files
with
183 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
erigon-lib/downloader/downloaderrawdb/accessors_downloader.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package downloaderrawdb | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/erigontech/erigon-lib/kv" | ||
) | ||
|
||
type TorrentInfo struct { | ||
Name string `json:"name"` | ||
Hash []byte `json:"hash"` | ||
Length *int64 `json:"length,omitempty"` | ||
Created *time.Time `json:"created,omitempty"` | ||
Completed *time.Time `json:"completed,omitempty"` | ||
} | ||
|
||
func ReadTorrentInfo(downloaderDBTx kv.Tx, name string) (*TorrentInfo, error) { | ||
var info TorrentInfo | ||
infoBytes, err := downloaderDBTx.GetOne(kv.BittorrentInfo, []byte(name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(infoBytes) == 0 { | ||
return &info, nil | ||
} | ||
if err = json.Unmarshal(infoBytes, &info); err != nil { | ||
return nil, err | ||
} | ||
return &info, nil | ||
} | ||
|
||
func ReadTorrentInfoHash(downloaderDBTx kv.Tx, name string) (hashBytes []byte, err error) { | ||
infoBytes, err := downloaderDBTx.GetOne(kv.BittorrentInfo, []byte(name)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if len(infoBytes) == 20 { | ||
return infoBytes, nil | ||
} | ||
|
||
var info TorrentInfo | ||
if err = json.Unmarshal(infoBytes, &info); err == nil { | ||
return info.Hash, nil | ||
} | ||
return nil, nil | ||
} | ||
|
||
func WriteTorrentInfo(tx kv.RwTx, info *TorrentInfo) error { | ||
infoBytes, err := json.Marshal(info) | ||
if err != nil { | ||
return err | ||
} | ||
return tx.Put(kv.BittorrentInfo, []byte(info.Name), infoBytes) | ||
} | ||
|
||
func CheckFileComplete(tx kv.Tx, name string, snapDir string) (bool, int64, *time.Time) { | ||
info, err := ReadTorrentInfo(tx, name) | ||
if err != nil { | ||
return false, 0, nil | ||
} | ||
if info.Completed != nil && info.Completed.Before(time.Now()) { | ||
if info.Length != nil { | ||
if fi, err := os.Stat(filepath.Join(snapDir, name)); err == nil { | ||
return fi.Size() == *info.Length && fi.ModTime().Equal(*info.Completed), *info.Length, info.Completed | ||
} | ||
} | ||
} | ||
return false, 0, nil | ||
} |
Oops, something went wrong.