Skip to content

Commit dee79a3

Browse files
committed
Merge PR #927 from 'rithvikvibhu/end-airdrop'
2 parents f0a81da + 4782714 commit dee79a3

File tree

6 files changed

+578
-35
lines changed

6 files changed

+578
-35
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
**When upgrading to this version of hsd, you must pass `--chain-migrate=4`
66
and `--wallet-migrate=7` when you run it for the first time.**
77

8+
### Network
9+
10+
**End Airdrop soft fork has been included. ([#927](https://github.com/handshake-org/hsd/pull/927))
11+
Miners who want to support the soft-fork need to start signalling with `airstop` bit.**
12+
813
### Wallet Changes
914

1015
#### Wallet HTTP API
@@ -213,6 +218,11 @@ The following methods have been deprecated:
213218

214219
## v6.0.0
215220

221+
### Network
222+
223+
**ICANN Lockup soft fork has been included. ([#819](https://github.com/handshake-org/hsd/pull/819), [#828](https://github.com/handshake-org/hsd/pull/828), [#834](https://github.com/handshake-org/hsd/pull/834))
224+
Miners who want to support the soft-fork need to start signalling with `icannlockup` bit.**
225+
216226
### Node and Wallet HTTP API
217227
Validation errors, request paremeter errors or bad HTTP requests will no
218228
longer return (and log) `500` status code, instead will return `400`.

lib/blockchain/chain.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,14 @@ class Chain extends AsyncEmitter {
644644

645645
// Airdrop proof.
646646
if (!output.covenant.isClaim()) {
647+
// Disable airdrop claims if airstop is activated
648+
if (state.hasAirstop) {
649+
throw new VerifyError(block,
650+
'invalid',
651+
'bad-airdrop-disabled',
652+
100);
653+
}
654+
647655
let proof;
648656
try {
649657
proof = AirdropProof.decode(witness.items[0]);
@@ -739,6 +747,10 @@ class Chain extends AsyncEmitter {
739747
if (await this.isActive(prev, deployments.icannlockup))
740748
state.nameFlags |= rules.nameFlags.VERIFY_COVENANTS_LOCKUP;
741749

750+
// Disable airdrop claims.
751+
if (await this.isActive(prev, deployments.airstop))
752+
state.hasAirstop = true;
753+
742754
return state;
743755
}
744756

@@ -762,6 +774,9 @@ class Chain extends AsyncEmitter {
762774
if (!this.state.hasICANNLockup() && state.hasICANNLockup())
763775
this.logger.warning('ICANN lockup has been activated.');
764776

777+
if (!this.state.hasAirstop && state.hasAirstop)
778+
this.logger.warning('Airdrop claims has been disabled.');
779+
765780
this.state = state;
766781
}
767782

@@ -4115,6 +4130,7 @@ class DeploymentState {
41154130
this.flags = Script.flags.MANDATORY_VERIFY_FLAGS;
41164131
this.lockFlags = common.MANDATORY_LOCKTIME_FLAGS;
41174132
this.nameFlags = rules.MANDATORY_VERIFY_COVENANT_FLAGS;
4133+
this.hasAirstop = false;
41184134
}
41194135

41204136
hasHardening() {

lib/mempool/mempool.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ const Claim = require('../primitives/claim');
4141
const AirdropProof = require('../primitives/airdropproof');
4242
const {types} = rules;
4343

44+
/** @typedef {import('../types').Hash} Hash */
45+
/** @typedef {import('../blockchain/chainentry')} ChainEntry */
46+
4447
/**
4548
* Mempool
4649
* Represents a mempool.
@@ -274,6 +277,7 @@ class Mempool extends EventEmitter {
274277
// for a now expired name. Another
275278
// example is a stale BID for a name
276279
// which has now reached the REVEAL state.
280+
const prevState = this.nextState;
277281
const state = await this.getNextState();
278282
const hardened = state.hasHardening();
279283
const invalid = this.contracts.invalidate(block.height, hardened);
@@ -316,13 +320,18 @@ class Mempool extends EventEmitter {
316320
}
317321
}
318322

323+
// If the next block activates airstop we drop any leftover proofs,
324+
// they can no longer be mined.
325+
if (!prevState.hasAirstop && state.hasAirstop)
326+
this.dropAirdrops();
327+
319328
this.cache.sync(block.hash);
320329

321330
await this.cache.flush();
322331

323332
this.tip = block.hash;
324333

325-
if (invalid.length > 0) {
334+
if (invalid.size > 0) {
326335
this.logger.info(
327336
'Invalidated %d txs for block %d.',
328337
invalid.size, block.height);
@@ -375,7 +384,7 @@ class Mempool extends EventEmitter {
375384
const proof = AirdropProof.decode(witness.items[0]);
376385
const entry = AirdropEntry.fromAirdrop(proof, this.chain.height);
377386

378-
this.trackAirdrop(entry, -1);
387+
this.trackAirdrop(entry);
379388

380389
continue;
381390
}
@@ -387,7 +396,7 @@ class Mempool extends EventEmitter {
387396

388397
const entry = ClaimEntry.fromClaim(claim, data, this.chain.height);
389398

390-
this.trackClaim(entry, -1);
399+
this.trackClaim(entry);
391400
}
392401

393402
let total = 0;
@@ -1048,11 +1057,10 @@ class Mempool extends EventEmitter {
10481057
* fully processed.
10491058
* @method
10501059
* @param {Claim} claim
1051-
* @param {Number?} id
10521060
* @returns {Promise}
10531061
*/
10541062

1055-
async addClaim(claim, id) {
1063+
async addClaim(claim) {
10561064
if (this.chain.height + 1 < this.network.txStart) {
10571065
throw new VerifyError(claim,
10581066
'invalid',
@@ -1063,7 +1071,7 @@ class Mempool extends EventEmitter {
10631071
const hash = claim.hash();
10641072
const unlock = await this.locker.lock(hash);
10651073
try {
1066-
return await this._addClaim(claim, id);
1074+
return await this._addClaim(claim);
10671075
} finally {
10681076
unlock();
10691077
}
@@ -1074,15 +1082,11 @@ class Mempool extends EventEmitter {
10741082
* @method
10751083
* @private
10761084
* @param {Claim} claim
1077-
* @param {Number?} id
10781085
* @returns {Promise}
10791086
*/
10801087

1081-
async _addClaim(claim, id) {
1082-
if (id == null)
1083-
id = -1;
1084-
1085-
await this.insertClaim(claim, id);
1088+
async _addClaim(claim) {
1089+
await this.insertClaim(claim);
10861090

10871091
if (util.now() - this.lastFlush > 10) {
10881092
await this.cache.flush();
@@ -1095,11 +1099,10 @@ class Mempool extends EventEmitter {
10951099
* @method
10961100
* @private
10971101
* @param {Claim} claim
1098-
* @param {Number?} id
10991102
* @returns {Promise}
11001103
*/
11011104

1102-
async insertClaim(claim, id) {
1105+
async insertClaim(claim) {
11031106
const height = this.chain.height + 1;
11041107
const tip = this.chain.tip;
11051108
const hash = claim.hash();
@@ -1175,7 +1178,7 @@ class Mempool extends EventEmitter {
11751178

11761179
const entry = ClaimEntry.fromClaim(claim, data, this.chain.height);
11771180

1178-
this.trackClaim(entry, id);
1181+
this.trackClaim(entry);
11791182

11801183
// Trim size if we're too big.
11811184
if (this.limitSize(hash)) {
@@ -1192,10 +1195,9 @@ class Mempool extends EventEmitter {
11921195
/**
11931196
* Track claim entry.
11941197
* @param {ClaimEntry} entry
1195-
* @param {Number} id
11961198
*/
11971199

1198-
trackClaim(entry, id) {
1200+
trackClaim(entry) {
11991201
assert(!this.claims.has(entry.hash));
12001202
assert(!this.claimNames.has(entry.nameHash));
12011203

@@ -1213,7 +1215,6 @@ class Mempool extends EventEmitter {
12131215
/**
12141216
* Untrack claim entry.
12151217
* @param {ClaimEntry} entry
1216-
* @param {Number} id
12171218
*/
12181219

12191220
untrackClaim(entry) {
@@ -1261,11 +1262,10 @@ class Mempool extends EventEmitter {
12611262
* fully processed.
12621263
* @method
12631264
* @param {AirdropProof} proof
1264-
* @param {Number?} id
12651265
* @returns {Promise}
12661266
*/
12671267

1268-
async addAirdrop(proof, id) {
1268+
async addAirdrop(proof) {
12691269
if (this.chain.height + 1 < this.network.txStart) {
12701270
throw new VerifyError(proof,
12711271
'invalid',
@@ -1276,7 +1276,7 @@ class Mempool extends EventEmitter {
12761276
const hash = proof.hash();
12771277
const unlock = await this.locker.lock(hash);
12781278
try {
1279-
return await this._addAirdrop(proof, id);
1279+
return await this._addAirdrop(proof);
12801280
} finally {
12811281
unlock();
12821282
}
@@ -1287,15 +1287,11 @@ class Mempool extends EventEmitter {
12871287
* @method
12881288
* @private
12891289
* @param {AirdropProof} proof
1290-
* @param {Number?} id
12911290
* @returns {Promise}
12921291
*/
12931292

1294-
async _addAirdrop(proof, id) {
1295-
if (id == null)
1296-
id = -1;
1297-
1298-
await this.insertAirdrop(proof, id);
1293+
async _addAirdrop(proof) {
1294+
await this.insertAirdrop(proof);
12991295

13001296
if (util.now() - this.lastFlush > 10) {
13011297
await this.cache.flush();
@@ -1308,11 +1304,10 @@ class Mempool extends EventEmitter {
13081304
* @method
13091305
* @private
13101306
* @param {AirdropProof} proof
1311-
* @param {Number?} id
13121307
* @returns {Promise}
13131308
*/
13141309

1315-
async insertAirdrop(proof, id) {
1310+
async insertAirdrop(proof) {
13161311
const hash = proof.hash();
13171312

13181313
// We can maybe ignore this.
@@ -1326,6 +1321,9 @@ class Mempool extends EventEmitter {
13261321
if (!proof.isSane())
13271322
throw new VerifyError(proof, 'invalid', 'bad-airdrop-proof', 100);
13281323

1324+
if (this.nextState.hasAirstop)
1325+
throw new VerifyError(proof, 'invalid', 'bad-airdrop-disabled', 0);
1326+
13291327
if (this.chain.height + 1 >= this.network.goosigStop) {
13301328
const key = proof.getKey();
13311329

@@ -1365,7 +1363,7 @@ class Mempool extends EventEmitter {
13651363

13661364
const entry = AirdropEntry.fromAirdrop(proof, this.chain.height);
13671365

1368-
this.trackAirdrop(entry, id);
1366+
this.trackAirdrop(entry);
13691367

13701368
// Trim size if we're too big.
13711369
if (this.limitSize(hash)) {
@@ -1382,10 +1380,9 @@ class Mempool extends EventEmitter {
13821380
/**
13831381
* Track airdrop proof entry.
13841382
* @param {AirdropEntry} entry
1385-
* @param {Number} id
13861383
*/
13871384

1388-
trackAirdrop(entry, id) {
1385+
trackAirdrop(entry) {
13891386
assert(!this.airdrops.has(entry.hash));
13901387
assert(!this.airdropIndex.has(entry.position));
13911388

@@ -1402,7 +1399,6 @@ class Mempool extends EventEmitter {
14021399
/**
14031400
* Untrack airdrop proof entry.
14041401
* @param {AirdropEntry} entry
1405-
* @param {Number} id
14061402
*/
14071403

14081404
untrackAirdrop(entry) {
@@ -2557,7 +2553,7 @@ class Mempool extends EventEmitter {
25572553
* Map a transaction to the mempool.
25582554
* @private
25592555
* @param {MempoolEntry} entry
2560-
* @param {CoinView} view
2556+
* @param {CoinView} [view]
25612557
*/
25622558

25632559
trackEntry(entry, view) {

0 commit comments

Comments
 (0)