Improved block sync speed

-A number of functions have been rewritten to be more optimized and faster: calculate_total, is_unique, convert_to_satoshi, get_input_addresses, processVoutAddresses, prepare_vout, prepare_vin
-Txes are now written to database via bulk writes which helps improve the sync speed and also controls memory usage with batching to write data once a certain threshold is reached
-update_address function changed to update_addresses since it now bulk writes the addresses in batches to improve sync speed and also controls memory usage with batching to write data once a certain threshold is reached
-The syncLoop function has been completely removed from the project and replaced with async library loops or even normal "for" loops in some cases which greatly improves sync speeds over large batches of data
-Fixed an issue with the flattened count of txes that is saved to the coinstats collection which could save incorrectly when using more than 1 thread
-Fixed an issue with the block sync which caused an unwanted delay when syncing less blocks than the amount of threads used to sync the data
-Fixed an issue with vout data processing that could sometimes populate data out of order
-Added a new sync.batch_size setting used to determine how many records (txes, addresses, addresstxes) should be saved in a single database transaction
-Added a new wait_for_bulk_database_save setting used to increase the block sync speed at the cost of not returning any error msgs for data that failed to save
-get_input_addresses function no longer returns in the exports section of the explorer.js file since it is only referenced in that file
-Updated explorerspec tests to use the newest function changes for any tests that needed to be updated

Special thanks to Karzo from Pepecoin for help with the bulkwrite code changes!
This commit is contained in:
Joe Uhren
2025-02-02 19:10:17 -07:00
parent 0b0ef817f1
commit 3a2f679201
10 changed files with 966 additions and 867 deletions
+19 -31
View File
@@ -4,21 +4,18 @@ describe('explorer', function() {
describe('convert_to_satoshi', function() {
it('should be able to convert round numbers', function() {
lib.convert_to_satoshi(500, function(amount_sat) {
expect(amount_sat).toEqual(50000000000);
});
const amount_sat = lib.convert_to_satoshi(500);
expect(amount_sat).toEqual(50000000000);
});
it('should be able to convert decimals above 1', function() {
lib.convert_to_satoshi(500.12564, function(amount_sat) {
expect(amount_sat).toEqual(50012564000);
});
const amount_sat = lib.convert_to_satoshi(500.12564);
expect(amount_sat).toEqual(50012564000);
});
it('should be able to convert decimals below 1', function() {
lib.convert_to_satoshi(0.0005, function(amount_sat) {
expect(amount_sat).toEqual(50000);
});
const amount_sat = lib.convert_to_satoshi(0.0005);
expect(amount_sat).toEqual(50000);
});
});
@@ -38,31 +35,23 @@ describe('explorer', function() {
];
it('should return index of matching string object', function() {
lib.is_unique(arrayStrMap, arrayStrMap[2].addresses, 'addresses', function(unique, index) {
expect(index).toEqual(2);
expect(unique).toEqual(false);
});
const index = lib.is_unique(arrayStrMap, arrayStrMap[2].addresses, 'addresses');
expect(index).toEqual(2);
});
it('should return index of matching array object', function() {
lib.is_unique(arrayArrMap, arrayArrMap[2].addresses, 'addresses', function(unique, index) {
expect(index).toEqual(2);
expect(unique).toEqual(false);
});
const index = lib.is_unique(arrayArrMap, arrayArrMap[2].addresses, 'addresses');
expect(index).toEqual(2);
});
it('should return true if no matching string object', function() {
lib.is_unique(arrayStrMap, 'unique', 'addresses', function(unique, index) {
expect(index).toEqual(null);
expect(unique).toEqual(true);
});
it('should return index of -1 if no matching string object', function() {
const index = lib.is_unique(arrayStrMap, 'unique', 'addresses');
expect(index).toEqual(-1);
});
it('should return true if no matching array object', function() {
lib.is_unique(arrayArrMap, ['unique'], 'addresses', function(unique, index) {
expect(index).toEqual(null);
expect(unique).toEqual(true);
});
it('should return index of -1 if no matching array object', function() {
const index = lib.is_unique(arrayArrMap, ['unique'], 'addresses');
expect(index).toEqual(-1);
});
});
@@ -104,10 +93,9 @@ describe('explorer', function() {
it('should calculate correct total', function(done) {
lib.prepare_vout(data.txA().vout, data.txA().txid, data.txA().vin, ((typeof data.txA().vjoinsplit === 'undefined' || data.txA().vjoinsplit == null) ? [] : data.txA().vjoinsplit), function(prepared) {
lib.calculate_total(prepared, function(total) {
expect(total).toEqual(19499989908960);
done();
});
const total = lib.calculate_total(prepared)
expect(total).toEqual(19499989908960);
done();
});
});