Commit 94455257 authored by 0x1337's avatar 0x1337

adding syncstatus check

parent 6336d1aa
......@@ -1182,9 +1182,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
// Some other error occurred, abort
case err != nil:
fmt.Println("this is here : 1185")
stats.ignored += len(it.chain)
bc.reportBlock(block, nil, err)
SyncStatus = false
return it.index, events, coalescedLogs, err
}
// No validation errors for the first block (or chain prefix skipped)
......@@ -1216,7 +1216,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
receipts, logs, usedGas, err := bc.processor.Process(block, state, bc.vmConfig)
t1 := time.Now()
if err != nil {
fmt.Println("this is here : 1219")
bc.reportBlock(block, receipts, err)
return it.index, events, coalescedLogs, err
}
......
......@@ -2,13 +2,15 @@ package core
import (
"errors"
"sort"
"git.pirl.io/community/pirl/core/types"
"git.pirl.io/community/pirl/log"
"git.pirl.io/community/pirl/params"
"sort"
)
var syncStatus bool
var SyncStatus bool
func (bc *BlockChain) checkChainForAttack(blocks types.Blocks) error {
// Copyright 2014 The go-ethereum Authors
// Copyright 2018 Pirl Sprl
......@@ -33,21 +35,18 @@ func (bc *BlockChain) checkChainForAttack(blocks types.Blocks) error {
timeMap := make(map[uint64]int64)
tipOfTheMainChain := bc.CurrentBlock().NumberU64()
if !syncStatus {
if tipOfTheMainChain == blocks[0].NumberU64() - 1 {
if !SyncStatus {
if tipOfTheMainChain == blocks[0].NumberU64()-1 {
//fmt.Println("We are synced")
syncStatus = true
SyncStatus = true
} else {
//fmt.Println("Still syncing!")
syncStatus = false
SyncStatus = false
}
}
if len(blocks) > 0 && bc.CurrentBlock().NumberU64() > uint64(params.TimeCapsuleBlock) {
if syncStatus && len(blocks) > int(params.TimeCapsuleLength) {
if SyncStatus && len(blocks) > int(params.TimeCapsuleLength) {
for _, b := range blocks {
timeMap[b.NumberU64()] = calculatePenaltyTimeForBlock(tipOfTheMainChain, b.NumberU64())
}
......@@ -56,7 +55,7 @@ func (bc *BlockChain) checkChainForAttack(blocks types.Blocks) error {
p := make(PairList, len(timeMap))
index := 0
for k, v := range timeMap {
p[index] = Pair {k, v}
p[index] = Pair{k, v}
index++
}
sort.Sort(p)
......@@ -73,16 +72,16 @@ func (bc *BlockChain) checkChainForAttack(blocks types.Blocks) error {
}
//fmt.Println("Penalty value for the chain :", penalty)
context := []interface{}{
"synced", syncStatus, "number", tipOfTheMainChain, "incoming_number", blocks[0].NumberU64() - 1, "penalty", penalty ,"implementation", "The Pirl Team",
"synced", SyncStatus, "number", tipOfTheMainChain, "incoming_number", blocks[0].NumberU64() - 1, "penalty", penalty, "implementation", "The Pirl Team",
}
log.Info("checking legitimity of the chain", context... )
log.Info("checking legitimity of the chain", context...)
if penalty > 0 {
context := []interface{}{
"penalty", penalty,
}
log.Error("Chain is a malicious and we should reject it", context... )
log.Error("Chain is a malicious and we should reject it", context...)
err = ErrDelayTooHigh
}
......@@ -94,7 +93,7 @@ func (bc *BlockChain) checkChainForAttack(blocks types.Blocks) error {
return err
}
func calculatePenaltyTimeForBlock(tipOfTheMainChain , incomingBlock uint64) int64 {
func calculatePenaltyTimeForBlock(tipOfTheMainChain, incomingBlock uint64) int64 {
if incomingBlock < tipOfTheMainChain {
return int64(tipOfTheMainChain - incomingBlock)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment