mirror of
https://github.com/mempool/mempool.git
synced 2024-11-19 09:52:14 +01:00
Add sequence number to mempool block updates
This commit is contained in:
parent
5697486cea
commit
3e6d38656d
@ -54,6 +54,7 @@ class WebsocketHandler {
|
|||||||
private socketData: { [key: string]: string } = {};
|
private socketData: { [key: string]: string } = {};
|
||||||
private serializedInitData: string = '{}';
|
private serializedInitData: string = '{}';
|
||||||
private lastRbfSummary: ReplacementInfo[] | null = null;
|
private lastRbfSummary: ReplacementInfo[] | null = null;
|
||||||
|
private mempoolSequence: number = 0;
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
@ -317,6 +318,7 @@ class WebsocketHandler {
|
|||||||
const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions();
|
const mBlocksWithTransactions = mempoolBlocks.getMempoolBlocksWithTransactions();
|
||||||
response['projected-block-transactions'] = JSON.stringify({
|
response['projected-block-transactions'] = JSON.stringify({
|
||||||
index: index,
|
index: index,
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
blockTransactions: (mBlocksWithTransactions[index]?.transactions || []).map(mempoolBlocks.compressTx),
|
blockTransactions: (mBlocksWithTransactions[index]?.transactions || []).map(mempoolBlocks.compressTx),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -602,6 +604,10 @@ class WebsocketHandler {
|
|||||||
const addressCache = this.makeAddressCache(newTransactions);
|
const addressCache = this.makeAddressCache(newTransactions);
|
||||||
const removedAddressCache = this.makeAddressCache(deletedTransactions);
|
const removedAddressCache = this.makeAddressCache(deletedTransactions);
|
||||||
|
|
||||||
|
if (memPool.isInSync()) {
|
||||||
|
this.mempoolSequence++;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - Fix indentation after PR is merged
|
// TODO - Fix indentation after PR is merged
|
||||||
for (const server of this.webSocketServers) {
|
for (const server of this.webSocketServers) {
|
||||||
server.clients.forEach(async (client) => {
|
server.clients.forEach(async (client) => {
|
||||||
@ -825,6 +831,7 @@ class WebsocketHandler {
|
|||||||
if (mBlockDeltas[index]) {
|
if (mBlockDeltas[index]) {
|
||||||
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-${index}`, {
|
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-${index}`, {
|
||||||
index: index,
|
index: index,
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
delta: mBlockDeltas[index],
|
delta: mBlockDeltas[index],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -993,6 +1000,9 @@ class WebsocketHandler {
|
|||||||
return responseCache[key];
|
return responseCache[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (memPool.isInSync()) {
|
||||||
|
this.mempoolSequence++;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO - Fix indentation after PR is merged
|
// TODO - Fix indentation after PR is merged
|
||||||
for (const server of this.webSocketServers) {
|
for (const server of this.webSocketServers) {
|
||||||
@ -1162,11 +1172,13 @@ class WebsocketHandler {
|
|||||||
if (mBlockDeltas[index].added.length > (mBlocksWithTransactions[index]?.transactions.length / 2)) {
|
if (mBlockDeltas[index].added.length > (mBlocksWithTransactions[index]?.transactions.length / 2)) {
|
||||||
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-full-${index}`, {
|
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-full-${index}`, {
|
||||||
index: index,
|
index: index,
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
blockTransactions: mBlocksWithTransactions[index].transactions.map(mempoolBlocks.compressTx),
|
blockTransactions: mBlocksWithTransactions[index].transactions.map(mempoolBlocks.compressTx),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-delta-${index}`, {
|
response['projected-block-transactions'] = getCachedResponse(`projected-block-transactions-delta-${index}`, {
|
||||||
index: index,
|
index: index,
|
||||||
|
sequence: this.mempoolSequence,
|
||||||
delta: mBlockDeltas[index],
|
delta: mBlockDeltas[index],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,7 @@ export class StateService {
|
|||||||
env: Env;
|
env: Env;
|
||||||
latestBlockHeight = -1;
|
latestBlockHeight = -1;
|
||||||
blocks: BlockExtended[] = [];
|
blocks: BlockExtended[] = [];
|
||||||
|
mempoolSequence: number;
|
||||||
|
|
||||||
backend$ = new BehaviorSubject<'esplora' | 'electrum' | 'none'>('esplora');
|
backend$ = new BehaviorSubject<'esplora' | 'electrum' | 'none'>('esplora');
|
||||||
networkChanged$ = new ReplaySubject<string>(1);
|
networkChanged$ = new ReplaySubject<string>(1);
|
||||||
|
@ -400,9 +400,16 @@ export class WebsocketService {
|
|||||||
if (response['projected-block-transactions']) {
|
if (response['projected-block-transactions']) {
|
||||||
if (response['projected-block-transactions'].index == this.trackingMempoolBlock) {
|
if (response['projected-block-transactions'].index == this.trackingMempoolBlock) {
|
||||||
if (response['projected-block-transactions'].blockTransactions) {
|
if (response['projected-block-transactions'].blockTransactions) {
|
||||||
|
this.stateService.mempoolSequence = response['projected-block-transactions'].sequence;
|
||||||
this.stateService.mempoolBlockTransactions$.next(response['projected-block-transactions'].blockTransactions.map(uncompressTx));
|
this.stateService.mempoolBlockTransactions$.next(response['projected-block-transactions'].blockTransactions.map(uncompressTx));
|
||||||
} else if (response['projected-block-transactions'].delta) {
|
} else if (response['projected-block-transactions'].delta) {
|
||||||
this.stateService.mempoolBlockDelta$.next(uncompressDeltaChange(response['projected-block-transactions'].delta));
|
if (this.stateService.mempoolSequence && response['projected-block-transactions'].sequence !== this.stateService.mempoolSequence + 1) {
|
||||||
|
this.stateService.mempoolSequence = 0;
|
||||||
|
this.startTrackMempoolBlock(this.trackingMempoolBlock, true);
|
||||||
|
} else {
|
||||||
|
this.stateService.mempoolSequence = response['projected-block-transactions'].sequence;
|
||||||
|
this.stateService.mempoolBlockDelta$.next(uncompressDeltaChange(response['projected-block-transactions'].delta));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user