From 0d393224ec0546df1b3ccc666892a8be83dc17bf Mon Sep 17 00:00:00 2001 From: Captain Date: Wed, 30 Dec 2020 04:39:59 +0000 Subject: [PATCH] DERO Homomorphic Encryption Testnet Release7 --- config/version.go | 2 +- p2p/chain_response.go | 12 +++++++++--- p2p/notification.go | 20 +++++++++++++++++++- p2p/object_response.go | 19 +++++++++++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/config/version.go b/config/version.go index f8154bf..9fefb1c 100644 --- a/config/version.go +++ b/config/version.go @@ -20,4 +20,4 @@ import "github.com/blang/semver" // right now it has to be manually changed // do we need to include git commitsha?? -var Version = semver.MustParse("3.0.0-23.DEROHE.alpha+27122020") +var Version = semver.MustParse("3.0.0-24.DEROHE.alpha+30122020") diff --git a/p2p/chain_response.go b/p2p/chain_response.go index 78555a6..515553e 100644 --- a/p2p/chain_response.go +++ b/p2p/chain_response.go @@ -74,7 +74,7 @@ func (connection *Connection) Handle_ChainResponse(buf []byte) { // we do not need reorganisation if deviation is less than or equak to 7 blocks // only pop blocks if the system has somehow deviated more than 7 blocks // if the deviation is less than 7 blocks, we internally reorganise everything - if chain.Load_TOPO_HEIGHT()-response.Start_topoheight >= config.STABLE_LIMIT && connection.SyncNode { + if chain.Get_Height() -response.Start_height > config.STABLE_LIMIT && connection.SyncNode { // get our top block rlog.Infof("rewinding status our %d peer %d", chain.Load_TOPO_HEIGHT(), response.Start_topoheight) pop_count := chain.Load_TOPO_HEIGHT() - response.Start_topoheight @@ -84,7 +84,12 @@ func (connection *Connection) Handle_ChainResponse(buf []byte) { connection.Send_ChainRequest() return - } + }else if chain.Get_Height()-response.Start_height <= config.STABLE_LIMIT { + pop_count := chain.Load_TOPO_HEIGHT() - response.Start_topoheight + chain.Rewind_Chain(int(pop_count)) // pop as many blocks as necessary, assumming peer has given us good chain + }else{ // we must somehow notify that deviation is way too much and manual interaction is necessary, so as any bug for chain deviationmay be detected + + } // response only 128 blocks at a time max_blocks_to_queue := 128 @@ -93,7 +98,8 @@ func (connection *Connection) Handle_ChainResponse(buf []byte) { rlog.Infof("response block list %d\n", len(response.Block_list)) for i := range response.Block_list { - if chain.Load_Block_Topological_order(response.Block_list[i]) == -1 { // if block is not in our chain, add it to request list + our_topo_order := chain.Load_Block_Topological_order(response.Block_list[i]) + if our_topo_order != (int64(i)+ response.Start_topoheight) || chain.Load_Block_Topological_order(response.Block_list[i]) == -1 { // if block is not in our chain, add it to request list //queue_block(request.Block_list[i]) if max_blocks_to_queue >= 0 { max_blocks_to_queue-- diff --git a/p2p/notification.go b/p2p/notification.go index 28b673a..73174bd 100644 --- a/p2p/notification.go +++ b/p2p/notification.go @@ -18,7 +18,7 @@ package p2p //import "fmt" //import "net" -//import "sync" +import "sync/atomic" import "time" import "encoding/binary" @@ -179,6 +179,24 @@ func (connection *Connection) Handle_Notification_Block(buf []byte) { } } +// make sure connection does not timeout and be killed while processing huge blocks + processing_complete := make(chan bool) + go func() { + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + for { + select { + case <- processing_complete: return // complete the loop + case <-ticker.C:// give the chain some more time to respond + atomic.StoreInt64(&connection.LastObjectRequestTime, time.Now().Unix()) + } + } + }() + + defer func() { + processing_complete <- true + }() + // check if we can add ourselves to chain if err, ok := chain.Add_Complete_Block(&cbl); ok { // if block addition was successfil // notify all peers diff --git a/p2p/object_response.go b/p2p/object_response.go index 7e7b5c6..afce8fd 100644 --- a/p2p/object_response.go +++ b/p2p/object_response.go @@ -69,6 +69,25 @@ func (connection *Connection) Handle_ObjectResponse(buf []byte) { rlog.Warnf("we got %d response for %d requests %s %s", len(response.CBlocks), len(expected.BLID), connection.logid) } + // make sure connection does not timeout and be killed while processing huge blocks + processing_complete := make(chan bool) + go func() { + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + for { + select { + case <- processing_complete: return // complete the loop + case <-ticker.C:// give the chain some more time to respond + atomic.StoreInt64(&connection.LastObjectRequestTime, time.Now().Unix()) + } + } + }() + + defer func() { + processing_complete <- true + }() + + for i := 0; i < len(response.CBlocks); i++ { // process incoming full blocks var cbl block.Complete_Block // parse incoming block and deserialize it var bl block.Block