Skip to content

Commit

Permalink
Merge pull request #472 from neonlabsorg/471_change_airdropper_startu…
Browse files Browse the repository at this point in the history
…p_logic

 471 Change Airdropper startup logic
  • Loading branch information
afalaleev authored Jan 21, 2022
2 parents 0409b80 + 6938431 commit 1529f93
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
34 changes: 19 additions & 15 deletions proxy/indexer/airdropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,19 @@ def __init__(self,
self._constants = SQLDict(tablename="constants")
if start_slot == 'CONTINUE':
self.info('Trying to use latest processed slot from previous run')
start_slot = self._constants.get('latest_processed_slot', 0)
start_slot = self._constants.get('latest_processed_slot', None)
if start_slot is None:
raise Exception('START_SLOT set to CONINUE but recent slot number not found in DB')
elif start_slot == 'LATEST':
self.info('Airdropper will start at latest blockchain slot')
client = SolanaClient(solana_url)
start_slot = client.get_slot(commitment=FINALIZED)["result"]
else:
try:
start_slot = int(start_slot)
except Exception as err:
self.warning(f'''Unsupported value for start_slot: {start_slot}.
Must be either integer value or one of [CONTINUE,LATEST]''')
raise
except:
raise Exception(f'Failed to parse start_slot value: {start_slot}')

self.info(f'Start slot is {start_slot}')

IndexerBase.__init__(self, solana_url, evm_loader_id, start_slot)
Expand Down Expand Up @@ -362,13 +363,16 @@ def run_airdropper(solana_url,
Price provider solana: {pp_solana_url},
Max confidence interval: {max_conf}""")

airdropper = Airdropper(solana_url,
evm_loader_id,
pyth_mapping_account,
faucet_url,
wrapper_whitelist,
neon_decimals,
start_slot,
pp_solana_url,
max_conf)
airdropper.run()
try:
airdropper = Airdropper(solana_url,
evm_loader_id,
pyth_mapping_account,
faucet_url,
wrapper_whitelist,
neon_decimals,
start_slot,
pp_solana_url,
max_conf)
airdropper.run()
except Exception as err:
logger.error(f'Failed to start Airdropper: {err}')
18 changes: 18 additions & 0 deletions proxy/testing/test_airdropper.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ def test_init_airdropper_slot_continue(self, mock_get_slot, mock_dict_get):
mock_dict_get.assert_called_once_with('latest_processed_slot', ANY)
mock_get_slot.assert_not_called()

@patch.object(SQLDict, 'get')
@patch.object(SolanaClient, 'get_slot')
def test_init_airdropper_slot_continue_recent_slot_not_found(self, mock_get_slot, mock_dict_get):
mock_dict_get.side_effect = [None]
with self.assertRaises(Exception):
self.create_airdropper('CONTINUE')
mock_dict_get.assert_called_once_with('latest_processed_slot', ANY)
mock_get_slot.assert_not_called()


@patch.object(SQLDict, 'get')
@patch.object(SolanaClient, 'get_slot')
def test_init_airdropper_start_slot_parse_error(self, mock_get_slot, mock_dict_get):
with self.assertRaises(Exception):
self.create_airdropper('Wrong value')
mock_dict_get.assert_not_called()
mock_get_slot.assert_not_called()


@patch.object(SQLDict, 'get')
@patch.object(SolanaClient, 'get_slot')
Expand Down

0 comments on commit 1529f93

Please sign in to comment.