Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fast sync and short chain #744

Merged
merged 2 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,7 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
}
// writeLive writes blockchain and corresponding receipt chain into active store.
writeLive := func(blockChain types.Blocks, receiptChain []types.Receipts) (int, error) {
skipPresenceCheck := false
batch := bc.db.NewBatch()
for i, block := range blockChain {
// Short circuit insertion if shutting down or processing failed
Expand All @@ -1266,9 +1267,17 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
if !bc.HasHeader(block.Hash(), block.NumberU64()) {
return i, fmt.Errorf("containing header #%d [%x…] unknown", block.Number(), block.Hash().Bytes()[:4])
}
if bc.HasBlock(block.Hash(), block.NumberU64()) {
stats.ignored++
continue
if !skipPresenceCheck {
// Ignore if the entire data is already known
if bc.HasBlock(block.Hash(), block.NumberU64()) {
stats.ignored++
continue
} else {
// If block N is not present, neither are the later blocks.
// This should be true, but if we are mistaken, the shortcut
// here will only cause overwriting of some existing data
skipPresenceCheck = true
}
}
// Write all the data out into the database
rawdb.WriteBody(batch, block.Hash(), block.NumberU64(), block.Body())
Expand Down
2 changes: 2 additions & 0 deletions ctxc/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,8 @@ func (d *Downloader) processHeaders(origin uint64, pivot uint64, td *big.Int) er
head := chunk[len(chunk)-1].Number.Uint64()
if head-rollback > uint64(fsHeaderSafetyNet) {
rollback = head - uint64(fsHeaderSafetyNet)
} else {
rollback = 1
}
}
// Unless we're doing light chains, schedule the headers for associated content retrieval
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/Azure/azure-storage-blob-go v0.8.1-0.20191213204130-762620a866ba
github.com/CortexFoundation/inference v0.0.0-20200819124612-ecf4b33bd901
github.com/CortexFoundation/torrentfs v1.0.20-0.20200819053011-10bee23abf91
github.com/CortexFoundation/torrentfs v1.0.20-0.20200821074238-37144679d7c8
github.com/VictoriaMetrics/fastcache v1.5.8-0.20200305212624-8835719dc76c
github.com/aristanetworks/goarista v0.0.0-20200513152637-638451432ae4
github.com/arsham/figurine v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.m
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200814090747-6d2d8ab19a8d h1:V1rOyN8MsrziwAenKE6DYIuskQSPkzV5Pu7nzy/pkEM=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200814090747-6d2d8ab19a8d/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200819053011-10bee23abf91 h1:qdEKayqBG4ikRrhnshS9kSlqYgdm1RAQwecQ4xLegzo=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200819053011-10bee23abf91/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200821074238-37144679d7c8 h1:w+lqlUVjlDMr+RlG5csIe+cEpFGmfXXP905m303xAAY=
github.com/CortexFoundation/torrentfs v1.0.20-0.20200821074238-37144679d7c8/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/Julusian/godocdown v0.0.0-20170816220326-6d19f8ff2df8/go.mod h1:INZr5t32rG59/5xeltqoCJoNY7e5x/3xoY9WSWVWg74=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/CortexFoundation/torrentfs/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions vendor/github.com/CortexFoundation/torrentfs/fs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/CortexFoundation/torrentfs/handler.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ github.com/CortexFoundation/cvm-runtime/kernel
## explicit
github.com/CortexFoundation/inference
github.com/CortexFoundation/inference/synapse
# github.com/CortexFoundation/torrentfs v1.0.20-0.20200819053011-10bee23abf91
# github.com/CortexFoundation/torrentfs v1.0.20-0.20200821074238-37144679d7c8
## explicit
github.com/CortexFoundation/torrentfs
github.com/CortexFoundation/torrentfs/compress
Expand Down