Skip to content

Download snapshot chunks #614

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

Merged
merged 17 commits into from
Mar 6, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ cover.out
coverage.*
.DS_Store
resource/zoobc_*
resource/snapshots
resource/snapshots*
resource_cluster/zoobc_*
cmd/*.new
accounts.txt
.manual
core/service/testdata/snapshots/*
10 changes: 5 additions & 5 deletions cmd/block/blockGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

type (
mockBlockTypeStatusService struct {
service.BlockTypeStatusService
mockBlockchainStatusService struct {
service.BlockchainStatusService
}
)

Expand Down Expand Up @@ -58,11 +58,11 @@ var (
}
)

func (*mockBlockTypeStatusService) IsFirstDownloadFinished(ct chaintype.ChainType) bool {
func (*mockBlockchainStatusService) IsFirstDownloadFinished(ct chaintype.ChainType) bool {
return true
}

func (*mockBlockTypeStatusService) IsDownloading(ct chaintype.ChainType) bool {
func (*mockBlockchainStatusService) IsDownloading(ct chaintype.ChainType) bool {
return true
}

Expand Down Expand Up @@ -209,7 +209,7 @@ func generateBlocks(numberOfBlocks int, blocksmithSecretPhrase, outputPath strin
blocksmith,
blockService,
log.New(),
&mockBlockTypeStatusService{},
&mockBlockchainStatusService{},
)
startTime := time.Now().UnixNano() / 1e6
fmt.Printf("generating %d blocks\n", numberOfBlocks)
Expand Down
7 changes: 3 additions & 4 deletions common/constant/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ const (
// BlockchainsyncWaitingTime time, in seconds, to wait before start syncing the blockchain
BlockchainsyncWaitingTime time.Duration = 5 * time.Second
// BlockchainsyncCheckInterval time, in seconds, between checks if spine blocks have finished to be downloaded
BlockchainsyncCheckInterval time.Duration = 10 * time.Second
BlockchainsyncCheckInterval time.Duration = 3 * time.Second
// BlockchainsyncSpineTimeout timeout, in seconds, for spine blocks to be downloaded from the network
// FIXME: this is for debugging purposes only and must higher on production,
// where downloading the spine blocks could take longer than 30 minutes
BlockchainsyncSpineTimeout time.Duration = 1800 * time.Second
// download spine blocks and snapshot (if present) timeout
BlockchainsyncSpineTimeout time.Duration = 3600 * time.Second
)
3 changes: 2 additions & 1 deletion common/constant/smith.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ var (
// CheckTimedOutBlock to use in scheduler to check timedout block while waiting transaction
CheckTimedOutBlock = 30 * time.Second
SpineChainSmithIdlePeriod = 500 * time.Millisecond
// SpineChainSmithingPeriod one spine block every 5 min
// SpineChainSmithingPeriod one spine block every 5 min (300 seconds)
// @iltoga reduce to 60 for testing locally
SpineChainSmithingPeriod = int64(300)
MainChainSmithIdlePeriod = 500 * time.Millisecond
// MainChainSmithingPeriod one main block every 15 seconds + block pool delay (max +30 seconds)
Expand Down
9 changes: 7 additions & 2 deletions common/constant/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import "time"

const (
// SnapshotGenerationTimeout maximum time, in seconds, allowed for a node to generate a snapshot
// @iltoga reduce to 1 for testing locally
MainchainSnapshotGenerationTimeout time.Duration = 10 * time.Minute // 10 minutes before including in spine block
// MainchainSnapshotInterval interval in mainchain blocks between snapshots
MainchainSnapshotInterval uint32 = 720 // 720 mainchain blocks (= MinRollbackHeight)
SnapshotChunkSize int = int(100 * 1024) // 100 KB
// @iltoga reduce to 5 for testing locally
MainchainSnapshotInterval uint32 = 720 // 720 mainchain blocks (= MinRollbackHeight)
// @iltoga reduce to 1 for testing locally
SnapshotChunkSize int = int(100 * 1024) // 10 KB
// DownloadSnapshotNumberOfRetries number of times to retry downloading failed snapshot file chunks from other peers
DownloadSnapshotNumberOfRetries uint32 = 3
)
131 changes: 131 additions & 0 deletions common/model/fileDownload.pb.go

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

53 changes: 53 additions & 0 deletions common/model/mapIntBool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package model

import "sync"

type MapIntBool struct {
sync.RWMutex
internal map[int32]bool
}

func NewMapIntBool() *MapIntBool {
return &MapIntBool{
internal: make(map[int32]bool),
}
}

func (rm *MapIntBool) Load(key int32) (value, ok bool) {
rm.RLock()
result, ok := rm.internal[key]
rm.RUnlock()
return result, ok
}

func (rm *MapIntBool) Delete(key int32) {
rm.Lock()
delete(rm.internal, key)
rm.Unlock()
}

func (rm *MapIntBool) Store(key int32, value bool) {
rm.Lock()
rm.internal[key] = value
rm.Unlock()
}

func (rm *MapIntBool) Count() int {
rm.RLock()
result := len(rm.internal)
rm.RUnlock()
return result
}

func (rm *MapIntBool) Reset() {
rm.Lock()
rm.internal = NewMapIntBool().internal
rm.Unlock()
}

func (rm *MapIntBool) GetMap() map[int32]bool {
rm.RLock()
result := rm.internal
rm.RUnlock()
return result
}
53 changes: 53 additions & 0 deletions common/model/mapStringInt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package model

import "sync"

type MapStringInt struct {
sync.RWMutex
internal map[string]int64
}

func NewMapStringInt() *MapStringInt {
return &MapStringInt{
internal: make(map[string]int64),
}
}

func (rm *MapStringInt) Load(key string) (value int64, ok bool) {
rm.RLock()
result, ok := rm.internal[key]
rm.RUnlock()
return result, ok
}

func (rm *MapStringInt) Delete(key string) {
rm.Lock()
delete(rm.internal, key)
rm.Unlock()
}

func (rm *MapStringInt) Store(key string, value int64) {
rm.Lock()
rm.internal[key] = value
rm.Unlock()
}

func (rm *MapStringInt) Count() int {
rm.RLock()
result := len(rm.internal)
rm.RUnlock()
return result
}

func (rm *MapStringInt) Reset() {
rm.Lock()
rm.internal = NewMapStringInt().internal
rm.Unlock()
}

func (rm *MapStringInt) GetMap() map[string]int64 {
rm.RLock()
result := rm.internal
rm.RUnlock()
return result
}
Loading