kopia lustrzana https://github.com/bugout-dev/moonstream
Option to run block sync from current block at Ethereum
rodzic
d23313c9d1
commit
e9d84f0a07
|
@ -88,21 +88,36 @@ def ethcrawler_blocks_sync_handler(args: argparse.Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
Synchronize latest Ethereum blocks with database.
|
Synchronize latest Ethereum blocks with database.
|
||||||
"""
|
"""
|
||||||
starting_block: int = args.start
|
|
||||||
while True:
|
while True:
|
||||||
bottom_block_number, top_block_number = get_latest_blocks(args.confirmations)
|
latest_stored_block_number, latest_block_number = get_latest_blocks(
|
||||||
if bottom_block_number is None:
|
args.confirmations
|
||||||
bottom_block_number = 0
|
)
|
||||||
bottom_block_number = max(bottom_block_number + 1, starting_block)
|
if latest_stored_block_number is None:
|
||||||
if bottom_block_number >= top_block_number:
|
latest_stored_block_number = 0
|
||||||
|
|
||||||
|
block_number_difference = latest_block_number - 1 - latest_stored_block_number
|
||||||
|
|
||||||
|
if args.start is None:
|
||||||
|
if block_number_difference < args.confirmations:
|
||||||
|
print(
|
||||||
|
f"Synchronization is unnecessary for blocks {latest_stored_block_number}-{latest_block_number - 1}"
|
||||||
|
)
|
||||||
|
time.sleep(5)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
bottom_block_number = latest_block_number - args.confirmations
|
||||||
|
else:
|
||||||
|
bottom_block_number = max(latest_stored_block_number + 1, args.start)
|
||||||
|
|
||||||
|
if latest_stored_block_number >= latest_block_number:
|
||||||
print(
|
print(
|
||||||
f"Synchronization is unnecessary for blocks {bottom_block_number}-{top_block_number - 1}"
|
f"Synchronization is unnecessary for blocks {latest_stored_block_number}-{latest_block_number - 1}"
|
||||||
)
|
)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for blocks_numbers_list in yield_blocks_numbers_lists(
|
for blocks_numbers_list in yield_blocks_numbers_lists(
|
||||||
f"{bottom_block_number}-{top_block_number}",
|
f"{bottom_block_number}-{latest_block_number}",
|
||||||
order=args.order,
|
order=args.order,
|
||||||
):
|
):
|
||||||
print(f"Adding blocks {blocks_numbers_list[-1]}-{blocks_numbers_list[0]}")
|
print(f"Adding blocks {blocks_numbers_list[-1]}-{blocks_numbers_list[0]}")
|
||||||
|
@ -112,7 +127,9 @@ def ethcrawler_blocks_sync_handler(args: argparse.Namespace) -> None:
|
||||||
with_transactions=not args.notransactions,
|
with_transactions=not args.notransactions,
|
||||||
num_processes=args.jobs,
|
num_processes=args.jobs,
|
||||||
)
|
)
|
||||||
print(f"Synchronized blocks from {bottom_block_number} to {top_block_number}")
|
print(
|
||||||
|
f"Synchronized blocks from {latest_stored_block_number} to {latest_block_number}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def ethcrawler_blocks_add_handler(args: argparse.Namespace) -> None:
|
def ethcrawler_blocks_add_handler(args: argparse.Namespace) -> None:
|
||||||
|
@ -243,8 +260,7 @@ def main() -> None:
|
||||||
"-s",
|
"-s",
|
||||||
"--start",
|
"--start",
|
||||||
type=int,
|
type=int,
|
||||||
default=0,
|
help="(Optional) Block to start synchronization from. Default: None - current Ethereum block minus confirmations ",
|
||||||
help="(Optional) Block to start synchronization from. Default: 0",
|
|
||||||
)
|
)
|
||||||
parser_ethcrawler_blocks_sync.add_argument(
|
parser_ethcrawler_blocks_sync.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
|
|
Ładowanie…
Reference in New Issue