Skip to content

Commit

Permalink
Merge pull request #17 from pnagurny/feature/ignore-p2p-txs
Browse files Browse the repository at this point in the history
Ignore p2p transactions while syncing
  • Loading branch information
Braydon Fuller committed Jul 13, 2015
2 parents ac3908f + a1d20df commit 63b316c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/p2p.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ function P2P(options) {
this.syncTimeout = options.syncTimeout || P2P.SYNC_TIMEOUT;
this.ready = false;
this.synced = false;
this.ignoreTransactions = true; // Ignore p2p transactions while syncing

this.on('synced', function() {
self.ignoreTransactions = false;
self.chain.lastSavedMetadataThreshold = 0;
self.chain.saveMetadata();
});
Expand Down Expand Up @@ -98,7 +100,7 @@ P2P.prototype._onPeerInv = function(peer, message) {

// check that we don't already have the data
var filtered = inventory.filter(function(a) {
if (a.type === Inventory.TYPE.TX) {
if (a.type === Inventory.TYPE.TX && !self.ignoreTransactions) {
return !self.mempool.hasTransaction(self._bufferToHash(a.hash));
} else if (a.type === Inventory.TYPE.BLOCK) {
return !self.mempool.hasBlock(self._bufferToHash(a.hash));
Expand Down
2 changes: 2 additions & 0 deletions test/p2p.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ describe('P2P Integration test', function() {

node1 = createNode1();
node1.on('ready', function() {
node1.p2p.ignoreTransactions = false;
node1Ready = true;
if(node2Ready) {
done();
Expand All @@ -111,6 +112,7 @@ describe('P2P Integration test', function() {

node2 = createNode2();
node2.on('ready', function() {
node2.p2p.ignoreTransactions = false;
node2Ready = true;
if(node1Ready) {
done();
Expand Down
1 change: 1 addition & 0 deletions test/p2p.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ describe('P2P', function() {
p2p.messages = {
GetData: sinon.spy()
};
p2p.ignoreTransactions = false;
var peerStub = {
sendMessage: sinon.spy()
};
Expand Down

0 comments on commit 63b316c

Please sign in to comment.