Merge pull request #1320 from antonilol/regtest-1

regtest fixes
This commit is contained in:
softsimon 2022-03-11 14:07:58 +01:00 committed by GitHub
commit 9dbfd96249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 19 deletions

View File

@ -41,7 +41,9 @@ class BitcoinApi implements AbstractBitcoinApi {
$getBlockHeightTip(): Promise<number> { $getBlockHeightTip(): Promise<number> {
return this.bitcoindClient.getChainTips() return this.bitcoindClient.getChainTips()
.then((result: IBitcoinApi.ChainTips[]) => result[0].height); .then((result: IBitcoinApi.ChainTips[]) => {
return result.find(tip => tip.status === 'active')!.height;
});
} }
$getTxIdsForBlock(hash: string): Promise<string[]> { $getTxIdsForBlock(hash: string): Promise<string[]> {

View File

@ -252,7 +252,7 @@ class Blocks {
const blockHeightTip = await bitcoinApi.$getBlockHeightTip(); const blockHeightTip = await bitcoinApi.$getBlockHeightTip();
if (this.blocks.length === 0) { if (this.blocks.length === 0) {
this.currentBlockHeight = blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT; this.currentBlockHeight = Math.max(blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT, -1);
} else { } else {
this.currentBlockHeight = this.blocks[this.blocks.length - 1].height; this.currentBlockHeight = this.blocks[this.blocks.length - 1].height;
} }
@ -271,17 +271,19 @@ class Blocks {
this.lastDifficultyAdjustmentTime = block.timestamp; this.lastDifficultyAdjustmentTime = block.timestamp;
this.currentDifficulty = block.difficulty; this.currentDifficulty = block.difficulty;
const previousPeriodBlockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff - 2016); if (blockHeightTip >= 2016) {
const previousPeriodBlock = await bitcoinApi.$getBlock(previousPeriodBlockHash); const previousPeriodBlockHash = await bitcoinApi.$getBlockHash(blockHeightTip - heightDiff - 2016);
this.previousDifficultyRetarget = (block.difficulty - previousPeriodBlock.difficulty) / previousPeriodBlock.difficulty * 100; const previousPeriodBlock = await bitcoinApi.$getBlock(previousPeriodBlockHash);
logger.debug(`Initial difficulty adjustment data set.`); this.previousDifficultyRetarget = (block.difficulty - previousPeriodBlock.difficulty) / previousPeriodBlock.difficulty * 100;
logger.debug(`Initial difficulty adjustment data set.`);
}
} else { } else {
logger.debug(`Blockchain headers (${blockchainInfo.headers}) and blocks (${blockchainInfo.blocks}) not in sync. Waiting...`); logger.debug(`Blockchain headers (${blockchainInfo.headers}) and blocks (${blockchainInfo.blocks}) not in sync. Waiting...`);
} }
} }
while (this.currentBlockHeight < blockHeightTip) { while (this.currentBlockHeight < blockHeightTip) {
if (this.currentBlockHeight === 0) { if (this.currentBlockHeight < blockHeightTip - config.MEMPOOL.INITIAL_BLOCKS_AMOUNT) {
this.currentBlockHeight = blockHeightTip; this.currentBlockHeight = blockHeightTip;
} else { } else {
this.currentBlockHeight++; this.currentBlockHeight++;

View File

@ -681,7 +681,7 @@ class Routes {
} }
let nextHash = startFromHash; let nextHash = startFromHash;
for (let i = 0; i < 10; i++) { for (let i = 0; i < 10 && nextHash; i++) {
const localBlock = blocks.getBlocks().find((b) => b.id === nextHash); const localBlock = blocks.getBlocks().find((b) => b.id === nextHash);
if (localBlock) { if (localBlock) {
returnBlocks.push(localBlock); returnBlocks.push(localBlock);

View File

@ -217,12 +217,8 @@ export class BlockComponent implements OnInit, OnDestroy {
this.blockSubsidy = 0; this.blockSubsidy = 0;
return; return;
} }
this.blockSubsidy = 50; const halvings = Math.floor(this.block.height / 210000);
let halvenings = Math.floor(this.block.height / 210000); this.blockSubsidy = 50 * 2 ** -halvings;
while (halvenings > 0) {
this.blockSubsidy = this.blockSubsidy / 2;
halvenings--;
}
} }
pageChange(page: number, target: HTMLElement) { pageChange(page: number, target: HTMLElement) {

View File

@ -110,7 +110,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
this.markBlockSubscription = this.stateService.markBlock$ this.markBlockSubscription = this.stateService.markBlock$
.subscribe((state) => { .subscribe((state) => {
this.markHeight = undefined; this.markHeight = undefined;
if (state.blockHeight) { if (state.blockHeight !== undefined) {
this.markHeight = state.blockHeight; this.markHeight = state.blockHeight;
} }
this.moveArrowToPosition(false); this.moveArrowToPosition(false);
@ -127,7 +127,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
} }
moveArrowToPosition(animate: boolean, newBlockFromLeft = false) { moveArrowToPosition(animate: boolean, newBlockFromLeft = false) {
if (!this.markHeight) { if (this.markHeight === undefined) {
this.arrowVisible = false; this.arrowVisible = false;
return; return;
} }

View File

@ -109,8 +109,12 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
if (this.isLoading) { if (this.isLoading) {
return; return;
} }
const height = this.blocks[this.blocks.length - 1].height - 1;
if (height < 0) {
return;
}
this.isLoading = true; this.isLoading = true;
this.electrsApiService.listBlocks$(this.blocks[this.blocks.length - 1].height - 1) this.electrsApiService.listBlocks$(height)
.subscribe((blocks) => { .subscribe((blocks) => {
this.blocks = this.blocks.concat(blocks); this.blocks = this.blocks.concat(blocks);
this.isLoading = false; this.isLoading = false;

View File

@ -144,6 +144,9 @@ export class DashboardComponent implements OnInit {
this.latestBlockHeight = block.height; this.latestBlockHeight = block.height;
}), }),
scan((acc, [block]) => { scan((acc, [block]) => {
if (acc.find((b) => b.height == block.height)) {
return acc;
}
acc.unshift(block); acc.unshift(block);
acc = acc.slice(0, 6); acc = acc.slice(0, 6);
return acc; return acc;
@ -153,6 +156,9 @@ export class DashboardComponent implements OnInit {
this.transactions$ = this.stateService.transactions$ this.transactions$ = this.stateService.transactions$
.pipe( .pipe(
scan((acc, tx) => { scan((acc, tx) => {
if (acc.find((t) => t.txid == tx.txid)) {
return acc;
}
acc.unshift(tx); acc.unshift(tx);
acc = acc.slice(0, 6); acc = acc.slice(0, 6);
return acc; return acc;

View File

@ -71,7 +71,7 @@ export class StateService {
network = ''; network = '';
blockVSize: number; blockVSize: number;
env: Env; env: Env;
latestBlockHeight = 0; latestBlockHeight = -1;
networkChanged$ = new ReplaySubject<string>(1); networkChanged$ = new ReplaySubject<string>(1);
blocks$: ReplaySubject<[BlockExtended, boolean]>; blocks$: ReplaySubject<[BlockExtended, boolean]>;

View File

@ -68,7 +68,7 @@ export class WebsocketService {
clearTimeout(this.onlineCheckTimeout); clearTimeout(this.onlineCheckTimeout);
clearTimeout(this.onlineCheckTimeoutTwo); clearTimeout(this.onlineCheckTimeoutTwo);
this.stateService.latestBlockHeight = 0; this.stateService.latestBlockHeight = -1;
this.websocketSubject.complete(); this.websocketSubject.complete();
this.subscription.unsubscribe(); this.subscription.unsubscribe();