Skip to content
Snippets Groups Projects
Commit cd699d75 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] sync: reject too old peers

parent d71bcf76
No related branches found
No related tags found
No related merge requests found
...@@ -302,7 +302,9 @@ export const CommonConstants = { ...@@ -302,7 +302,9 @@ export const CommonConstants = {
BLOCK_MAX_TX_CHAINING_DEPTH: 5, BLOCK_MAX_TX_CHAINING_DEPTH: 5,
CONST_BLOCKS_CHUNK: 250, CONST_BLOCKS_CHUNK: 250,
BLOCKS_IN_MEMORY_MAX: 288 * 60 // 60 days of blocks BLOCKS_IN_MEMORY_MAX: 288 * 60, // 60 days of blocks
MAX_AGE_OF_PEER_IN_BLOCKS: 200, // blocks
} }
function exact (regexpContent:string) { function exact (regexpContent:string) {
......
export enum DataErrors { export enum DataErrors {
TOO_OLD_PEER,
LOKI_DIVIDEND_GET_WRITTEN_ON_SHOULD_NOT_BE_USED, LOKI_DIVIDEND_GET_WRITTEN_ON_SHOULD_NOT_BE_USED,
LOKI_DIVIDEND_REMOVE_BLOCK_SHOULD_NOT_BE_USED, LOKI_DIVIDEND_REMOVE_BLOCK_SHOULD_NOT_BE_USED,
NEGATIVE_BALANCE, NEGATIVE_BALANCE,
......
...@@ -23,6 +23,8 @@ import {Server} from "../../server" ...@@ -23,6 +23,8 @@ import {Server} from "../../server"
import {GlobalFifoPromise} from "./GlobalFifoPromise" import {GlobalFifoPromise} from "./GlobalFifoPromise"
import {DBPeer} from "../lib/db/DBPeer" import {DBPeer} from "../lib/db/DBPeer"
import {Underscore} from "../lib/common-libs/underscore" import {Underscore} from "../lib/common-libs/underscore"
import {CommonConstants} from "../lib/common-libs/constants"
import {DataErrors} from "../lib/common-libs/errors"
const util = require('util'); const util = require('util');
const events = require('events'); const events = require('events');
...@@ -104,6 +106,7 @@ export class PeeringService { ...@@ -104,6 +106,7 @@ export class PeeringService {
} }
} }
if (thePeer.block == constants.PEER.SPECIAL_BLOCK) { if (thePeer.block == constants.PEER.SPECIAL_BLOCK) {
thePeer.block = constants.PEER.SPECIAL_BLOCK;
thePeer.statusTS = 0; thePeer.statusTS = 0;
thePeer.status = 'UP'; thePeer.status = 'UP';
} else { } else {
...@@ -115,6 +118,10 @@ export class PeeringService { ...@@ -115,6 +118,10 @@ export class PeeringService {
thePeer.statusTS = 0; thePeer.statusTS = 0;
thePeer.status = 'UP'; thePeer.status = 'UP';
} }
const current = await this.dal.getBlockCurrent()
if ((!block && current.number > CommonConstants.MAX_AGE_OF_PEER_IN_BLOCKS) || (block && current.number - block.number > CommonConstants.MAX_AGE_OF_PEER_IN_BLOCKS)) {
throw Error(DataErrors[DataErrors.TOO_OLD_PEER])
}
} }
sigTime = block ? block.medianTime : 0; sigTime = block ? block.medianTime : 0;
thePeer.statusTS = sigTime; thePeer.statusTS = sigTime;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment