Skip to content

357/359/377 - bug fixes #370

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 7 commits into from
Oct 28, 2019
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
1 change: 0 additions & 1 deletion common/query/accountBalanceQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ func (q *AccountBalanceQuery) Rollback(height uint32) (multiQueries [][]interfac
WHERE (block_height || '_' || account_address) IN (
SELECT (MAX(block_height) || '_' || account_address) as con
FROM %s
WHERE latest = 0
GROUP BY account_address
)`,
q.TableName,
Expand Down
1 change: 0 additions & 1 deletion common/query/accountBalanceQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ func TestAccountBalanceQuery_Rollback(t *testing.T) {
WHERE (block_height || '_' || account_address) IN (
SELECT (MAX(block_height) || '_' || account_address) as con
FROM account_balance
WHERE latest = 0
GROUP BY account_address
)`,
1,
Expand Down
1 change: 0 additions & 1 deletion common/query/accountDatasetsQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ func (adq *AccountDatasetsQuery) Rollback(height uint32) (multiQueries [][]inter
WHERE (%s) IN (
SELECT (%s) as con
FROM %s
WHERE latest = 0
GROUP BY %s
)`,
adq.TableName,
Expand Down
1 change: 0 additions & 1 deletion common/query/accountDatasetsQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,6 @@ func TestAccountDatasetsQuery_Rollback(t *testing.T) {
WHERE (%s) IN (
SELECT (%s) as con
FROM %s
WHERE latest = 0
GROUP BY %s
)`,
mockDatasetQuery.TableName,
Expand Down
1 change: 0 additions & 1 deletion common/query/nodeRegistrationQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ func (nrq *NodeRegistrationQuery) Rollback(height uint32) (multiQueries [][]inte
WHERE (height || '_' || id) IN (
SELECT (MAX(height) || '_' || id) as con
FROM %s
WHERE latest = 0
GROUP BY id
)`,
nrq.TableName,
Expand Down
1 change: 0 additions & 1 deletion common/query/nodeRegistrationQuery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ func TestNodeRegistrationQuery_Rollback(t *testing.T) {
WHERE (height || '_' || id) IN (
SELECT (MAX(height) || '_' || id) as con
FROM account_balance
WHERE latest = 0
GROUP BY id
)`,
1,
Expand Down
1 change: 0 additions & 1 deletion common/query/participationScoreQuery.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ func (ps *ParticipationScoreQuery) Rollback(height uint32) (multiQueries [][]int
WHERE height || '_' || id) IN (
SELECT (MAX(height) || '_' || id) as con
FROM %s
WHERE latest = 0
GROUP BY id
)`,
ps.TableName,
Expand Down
15 changes: 10 additions & 5 deletions core/blockchainsync/downloadBlockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (bd *BlockchainDownloader) DownloadFromPeer(feederPeer *model.Peer, chainBl
var (
peersTobeDeactivated []*model.Peer
peersSlice []*model.Peer
forkBlocks []*model.Block
)
segSize := constant.BlockDownloadSegSize

Expand Down Expand Up @@ -248,32 +249,36 @@ func (bd *BlockchainDownloader) DownloadFromPeer(feederPeer *model.Peer, chainBl
bd.PeerExplorer.DisconnectPeer(peer)
}

forkBlocks := []*model.Block{}
for _, block := range blocksToBeProcessed {
for idx, block := range blocksToBeProcessed {
if block.Height == 0 {
continue
}
lastBlock, err := bd.BlockService.GetLastBlock()
if err != nil {
return nil, err
}
if block.ID == lastBlock.ID && block.Height == lastBlock.Height {
continue
}
previousBlockID := coreUtil.GetBlockIDFromHash(block.PreviousBlockHash)
if lastBlock.ID == previousBlockID {
err := bd.BlockService.ValidateBlock(block, lastBlock, time.Now().Unix())
if err != nil {
// TODO: analyze the mechanism of blacklisting peer here
// bd.P2pService.Blacklist(peer)
bd.Logger.Infof("failed to verify block %v from peer: %s\n", block.ID, err)
bd.Logger.Infof("[download blockchain] failed to verify block %v from peer: %s\nwith previous: %v\n", block.ID, err, lastBlock.ID)
break
}
err = bd.BlockService.PushBlock(lastBlock, block, false, false)
if err != nil {
// TODO: analyze the mechanism of blacklisting peer here
// bd.P2pService.Blacklist(peer)
bd.Logger.Info("failed to push block from peer:", err)
break
}
} else {
forkBlocks = append(forkBlocks, block)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should there be special handle once notice fork block is pushed? I mean if we already notice a single fork block, that mean we won't be able to validate the rest of the block anymore right? but this is just an open question, I'm not sure about the overall implementation regarding the fork process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! I have handled it by breaking from the loop. Thank you

forkBlocks = blocksToBeProcessed[idx:]
break
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/blockchainsync/processFork.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (fp *ForkingProcessor) ProcessFork(forkBlocks []*model.Block, commonBlock *
if err != nil {
// TODO: analyze the mechanism of blacklisting peer here
// bd.P2pService.Blacklist(peer)
log.Warnf("failed to verify block %v from peer: %s\n", block.ID, err)
log.Warnf("[pushing fork block] failed to verify block %v from peer: %s\nwith previous: %v\n", block.ID, err, lastBlock.ID)
}
err = fp.BlockService.PushBlock(lastBlock, block, false, false)
if err != nil {
Expand Down Expand Up @@ -117,7 +117,7 @@ func (fp *ForkingProcessor) ProcessFork(forkBlocks []*model.Block, commonBlock *
if err != nil {
// TODO: analyze the mechanism of blacklisting peer here
// bd.P2pService.Blacklist(peer)
log.Warnf("failed to verify block %v from peer: %s\n", block.ID, err)
log.Warnf("[pushing back own block] failed to verify block %v from peer: %s\n with previous: %v\n", block.ID, err, lastBlock.ID)
return err
}
err = fp.BlockService.PushBlock(lastBlock, block, false, false)
Expand Down
4 changes: 2 additions & 2 deletions resource/config2.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ nodeKeyFile = "node_keys_2.json"
# Peer
peerPort=8002
myAddress="127.0.0.1"
wellknownPeers=["127.0.0.1:8002"]
wellknownPeers=["127.0.0.1:8001"]

apiRPCPort=3002
apiHTTPPort=3032
Expand All @@ -17,7 +17,7 @@ apiReqTimeoutSec=2

ownerAccountAddress = "OnEYzI-EMV6UTfoUEzpQUjkSlnqB82-SyRN7469lJTWH"

smithing=true
# smithing=true
proofOfOwnershipReqTimeoutSec = 1
# Log Levels
logLevels=["warn", "fatal", "error", "panic"]