Permit empty chain spec in ctl
This commit is contained in:
parent
6b3f936ead
commit
c2286e5c25
@ -32,6 +32,8 @@ def lock(chained_input, chain_spec_dict, address=ZERO_ADDRESS, flags=LockEnum.AL
|
|||||||
:returns: New lock state for address
|
:returns: New lock state for address
|
||||||
:rtype: number
|
:rtype: number
|
||||||
"""
|
"""
|
||||||
|
chain_str = '::'
|
||||||
|
if chain_spec_dict != None:
|
||||||
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
||||||
r = Lock.set(chain_str, flags, address=address, tx_hash=tx_hash)
|
r = Lock.set(chain_str, flags, address=address, tx_hash=tx_hash)
|
||||||
logg.debug('Locked {} for {}, flag now {}'.format(flags, address, r))
|
logg.debug('Locked {} for {}, flag now {}'.format(flags, address, r))
|
||||||
@ -51,6 +53,8 @@ def unlock(chained_input, chain_spec_dict, address=ZERO_ADDRESS, flags=LockEnum.
|
|||||||
:returns: New lock state for address
|
:returns: New lock state for address
|
||||||
:rtype: number
|
:rtype: number
|
||||||
"""
|
"""
|
||||||
|
chain_str = '::'
|
||||||
|
if chain_spec_dict != None:
|
||||||
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
||||||
r = Lock.reset(chain_str, flags, address=address)
|
r = Lock.reset(chain_str, flags, address=address)
|
||||||
logg.debug('Unlocked {} for {}, flag now {}'.format(flags, address, r))
|
logg.debug('Unlocked {} for {}, flag now {}'.format(flags, address, r))
|
||||||
@ -127,6 +131,8 @@ def unlock_queue(chained_input, chain_spec_dict, address=ZERO_ADDRESS):
|
|||||||
|
|
||||||
@celery_app.task(base=CriticalSQLAlchemyTask)
|
@celery_app.task(base=CriticalSQLAlchemyTask)
|
||||||
def check_lock(chained_input, chain_spec_dict, lock_flags, address=None):
|
def check_lock(chained_input, chain_spec_dict, lock_flags, address=None):
|
||||||
|
chain_str = '::'
|
||||||
|
if chain_spec_dict != None:
|
||||||
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
chain_str = str(ChainSpec.from_dict(chain_spec_dict))
|
||||||
session = SessionBase.create_session()
|
session = SessionBase.create_session()
|
||||||
r = Lock.check(chain_str, lock_flags, address=ZERO_ADDRESS, session=session)
|
r = Lock.check(chain_str, lock_flags, address=ZERO_ADDRESS, session=session)
|
||||||
|
@ -9,6 +9,9 @@ from chainlib.eth.gas import balance
|
|||||||
# local imports
|
# local imports
|
||||||
from cic_eth.db.models.role import AccountRole
|
from cic_eth.db.models.role import AccountRole
|
||||||
from cic_eth.db.models.base import SessionBase
|
from cic_eth.db.models.base import SessionBase
|
||||||
|
from cic_eth.db.enum import LockEnum
|
||||||
|
from cic_eth.error import LockedError
|
||||||
|
from cic_eth.admin.ctrl import check_lock
|
||||||
|
|
||||||
logg = logging.getLogger().getChild(__name__)
|
logg = logging.getLogger().getChild(__name__)
|
||||||
|
|
||||||
@ -17,9 +20,15 @@ def health(*args, **kwargs):
|
|||||||
|
|
||||||
session = SessionBase.create_session()
|
session = SessionBase.create_session()
|
||||||
|
|
||||||
logg.info('kwargs {} {}'.format(kwargs, args))
|
|
||||||
config = kwargs['config']
|
config = kwargs['config']
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
||||||
|
logg.debug('check gas balance of gas gifter for chain {}'.format(chain_spec))
|
||||||
|
|
||||||
|
try:
|
||||||
|
check_lock(None, None, LockEnum.INIT)
|
||||||
|
except LockedError:
|
||||||
|
logg.warning('INIT lock is set, skipping GAS GIFTER balance check.')
|
||||||
|
return True
|
||||||
|
|
||||||
gas_provider = AccountRole.get_address('GAS_GIFTER', session=session)
|
gas_provider = AccountRole.get_address('GAS_GIFTER', session=session)
|
||||||
session.close()
|
session.close()
|
||||||
@ -36,5 +45,4 @@ def health(*args, **kwargs):
|
|||||||
logg.error('EEK! gas gifter has balance {}, below minimum {}'.format(r, gas_min))
|
logg.error('EEK! gas gifter has balance {}, below minimum {}'.format(r, gas_min))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
return True
|
return True
|
@ -74,10 +74,11 @@ class LockEnum(enum.IntEnum):
|
|||||||
QUEUE: Disable queueing new or modified transactions
|
QUEUE: Disable queueing new or modified transactions
|
||||||
"""
|
"""
|
||||||
STICKY=1
|
STICKY=1
|
||||||
CREATE=2
|
INIT=2
|
||||||
SEND=4
|
CREATE=4
|
||||||
QUEUE=8
|
SEND=8
|
||||||
QUERY=16
|
QUEUE=16
|
||||||
|
QUERY=32
|
||||||
ALL=int(0xfffffffffffffffe)
|
ALL=int(0xfffffffffffffffe)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,8 +5,11 @@ Revises: 1f1b3b641d08
|
|||||||
Create Date: 2021-04-02 18:41:20.864265
|
Create Date: 2021-04-02 18:41:20.864265
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import datetime
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
from chainlib.eth.constant import ZERO_ADDRESS
|
||||||
|
from cic_eth.db.enum import LockEnum
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
@ -23,10 +26,11 @@ def upgrade():
|
|||||||
sa.Column("address", sa.String(42), nullable=True),
|
sa.Column("address", sa.String(42), nullable=True),
|
||||||
sa.Column('blockchain', sa.String),
|
sa.Column('blockchain', sa.String),
|
||||||
sa.Column("flags", sa.BIGINT(), nullable=False, default=0),
|
sa.Column("flags", sa.BIGINT(), nullable=False, default=0),
|
||||||
sa.Column("date_created", sa.DateTime, nullable=False),
|
sa.Column("date_created", sa.DateTime, nullable=False, default=datetime.datetime.utcnow),
|
||||||
sa.Column("otx_id", sa.Integer, sa.ForeignKey('otx.id'), nullable=True),
|
sa.Column("otx_id", sa.Integer, sa.ForeignKey('otx.id'), nullable=True),
|
||||||
)
|
)
|
||||||
op.create_index('idx_chain_address', 'lock', ['blockchain', 'address'], unique=True)
|
op.create_index('idx_chain_address', 'lock', ['blockchain', 'address'], unique=True)
|
||||||
|
op.execute("INSERT INTO lock (address, date_created, blockchain, flags) VALUES('{}', '{}', '::', {})".format(ZERO_ADDRESS, datetime.datetime.utcnow(), LockEnum.INIT | LockEnum.SEND | LockEnum.QUEUE))
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
@ -59,6 +59,7 @@ args_override = {
|
|||||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
||||||
}
|
}
|
||||||
# override args
|
# override args
|
||||||
|
config.dict_override(args_override, 'cli')
|
||||||
config.censor('PASSWORD', 'DATABASE')
|
config.censor('PASSWORD', 'DATABASE')
|
||||||
config.censor('PASSWORD', 'SSL')
|
config.censor('PASSWORD', 'SSL')
|
||||||
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
|
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
|
||||||
@ -67,7 +68,9 @@ celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=confi
|
|||||||
|
|
||||||
queue = args.q
|
queue = args.q
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
chain_spec = None
|
||||||
|
if config.get('CIC_CHAIN_SPEC') != None and config.get('CIC_CHAIN_SPEC') != '::':
|
||||||
|
chain_spec = ChainSpec.from_chain_str(config.get('CIC_CHAIN_SPEC'))
|
||||||
admin_api = AdminApi(None)
|
admin_api = AdminApi(None)
|
||||||
|
|
||||||
|
|
||||||
@ -82,6 +85,9 @@ def lock_names_to_flag(s):
|
|||||||
|
|
||||||
# TODO: move each command to submodule
|
# TODO: move each command to submodule
|
||||||
def main():
|
def main():
|
||||||
|
chain_spec_dict = None
|
||||||
|
if chain_spec != None:
|
||||||
|
chain_spec_dict = chain_spec.asdict()
|
||||||
if args.command == 'unlock':
|
if args.command == 'unlock':
|
||||||
flags = lock_names_to_flag(args.flags)
|
flags = lock_names_to_flag(args.flags)
|
||||||
if not is_checksum_address(args.address):
|
if not is_checksum_address(args.address):
|
||||||
@ -91,7 +97,7 @@ def main():
|
|||||||
'cic_eth.admin.ctrl.unlock',
|
'cic_eth.admin.ctrl.unlock',
|
||||||
[
|
[
|
||||||
None,
|
None,
|
||||||
chain_spec.asdict(),
|
chain_spec_dict,
|
||||||
args.address,
|
args.address,
|
||||||
flags,
|
flags,
|
||||||
],
|
],
|
||||||
@ -110,7 +116,7 @@ def main():
|
|||||||
'cic_eth.admin.ctrl.lock',
|
'cic_eth.admin.ctrl.lock',
|
||||||
[
|
[
|
||||||
None,
|
None,
|
||||||
chain_spec.asdict(),
|
chain_spec_dict,
|
||||||
args.address,
|
args.address,
|
||||||
flags,
|
flags,
|
||||||
],
|
],
|
||||||
|
@ -145,7 +145,7 @@ Otx.tracing = config.true('TASKS_TRACE_QUEUE_STATUS')
|
|||||||
#import cic_eth.checks.gas
|
#import cic_eth.checks.gas
|
||||||
#if not cic_eth.checks.gas.health(config=config):
|
#if not cic_eth.checks.gas.health(config=config):
|
||||||
# raise RuntimeError()
|
# raise RuntimeError()
|
||||||
liveness.linux.load(health_modules)
|
liveness.linux.load(health_modules, config=config)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
argv = ['worker']
|
argv = ['worker']
|
||||||
|
@ -3,4 +3,4 @@ registry_address =
|
|||||||
chain_spec = evm:bloxberg:8996
|
chain_spec = evm:bloxberg:8996
|
||||||
tx_retry_delay =
|
tx_retry_delay =
|
||||||
trust_address =
|
trust_address =
|
||||||
health_modules = cic_eth.k8s.db
|
health_modules = cic_eth.check.db,cic_eth.check.gas
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
[eth]
|
[eth]
|
||||||
provider = http://localhost:63545
|
provider = http://localhost:63545
|
||||||
gas_gifter_minimum_balance = 1000000000000000
|
health_modules = cic_eth.check.db,cic_eth.check.gas
|
||||||
|
gas_gifter_minimum_balance = 10000000000000000000000
|
||||||
|
@ -1,8 +1,4 @@
|
|||||||
[eth]
|
[eth]
|
||||||
#ws_provider = ws://localhost:8546
|
|
||||||
#ttp_provider = http://localhost:8545
|
|
||||||
provider = http://localhost:8545
|
provider = http://localhost:8545
|
||||||
gas_provider_address =
|
gas_gifter_minimum_balance = 10000000000000000000000
|
||||||
#chain_id =
|
health_modules = cic_eth.check.db,cic_eth.check.gas
|
||||||
abi_dir = /usr/local/share/cic/solidity/abi
|
|
||||||
account_accounts_index_writer =
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
cic-base==0.1.2a79+build.35e442bc
|
cic-base==0.1.2a79+build.d412618d
|
||||||
celery==4.4.7
|
celery==4.4.7
|
||||||
crypto-dev-signer~=0.4.14b2
|
crypto-dev-signer~=0.4.14b2
|
||||||
confini~=0.3.6rc3
|
confini~=0.3.6rc3
|
||||||
|
@ -38,7 +38,7 @@ packages =
|
|||||||
cic_eth.runnable.daemons.filters
|
cic_eth.runnable.daemons.filters
|
||||||
cic_eth.callbacks
|
cic_eth.callbacks
|
||||||
cic_eth.sync
|
cic_eth.sync
|
||||||
cic_eth.k8s
|
cic_eth.check
|
||||||
scripts =
|
scripts =
|
||||||
./scripts/migrate.py
|
./scripts/migrate.py
|
||||||
|
|
||||||
|
@ -46,6 +46,11 @@ DEV_ETH_ACCOUNT_GAS_GIFTER=`cic-eth-create $debug --redis-host-callback=$REDIS_H
|
|||||||
echo DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_GAS_GIFTER >> $env_out_file
|
echo DEV_ETH_ACCOUNT_GAS_GIFTER=$DEV_ETH_ACCOUNT_GAS_GIFTER >> $env_out_file
|
||||||
cic-eth-tag -i $CIC_CHAIN_SPEC GAS_GIFTER $DEV_ETH_ACCOUNT_GAS_GIFTER
|
cic-eth-tag -i $CIC_CHAIN_SPEC GAS_GIFTER $DEV_ETH_ACCOUNT_GAS_GIFTER
|
||||||
|
|
||||||
|
# Remove the SEND (8), QUEUE (16) and INIT (2) locks (or'ed), set by default at migration
|
||||||
|
cic-eth-ctl -i :: unlock INIT
|
||||||
|
cic-eth-ctl -i :: unlock SEND
|
||||||
|
cic-eth-ctl -i :: unlock QUEUE
|
||||||
|
|
||||||
>&2 echo "create account for sarafu gifter"
|
>&2 echo "create account for sarafu gifter"
|
||||||
DEV_ETH_ACCOUNT_SARAFU_GIFTER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
|
DEV_ETH_ACCOUNT_SARAFU_GIFTER=`cic-eth-create $debug --redis-host-callback=$REDIS_HOST --redis-port-callback=$REDIS_PORT --no-register`
|
||||||
echo DEV_ETH_ACCOUNT_SARAFU_GIFTER=$DEV_ETH_ACCOUNT_SARAFU_GIFTER >> $env_out_file
|
echo DEV_ETH_ACCOUNT_SARAFU_GIFTER=$DEV_ETH_ACCOUNT_SARAFU_GIFTER >> $env_out_file
|
||||||
|
@ -29,7 +29,7 @@ def load(check_strs, namespace=default_namespace, rundir='/run', *args, **kwargs
|
|||||||
checks.append(module)
|
checks.append(module)
|
||||||
|
|
||||||
for check in checks:
|
for check in checks:
|
||||||
r = check.health(args, kwargs)
|
r = check.health(*args, **kwargs)
|
||||||
if r == False:
|
if r == False:
|
||||||
raise RuntimeError('liveness check {} failed'.format(str(check)))
|
raise RuntimeError('liveness check {} failed'.format(str(check)))
|
||||||
logg.info('liveness check passed: {}'.format(str(check)))
|
logg.info('liveness check passed: {}'.format(str(check)))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
setup(
|
setup(
|
||||||
name='liveness',
|
name='liveness',
|
||||||
version='0.0.1a6',
|
version='0.0.1a7',
|
||||||
packages=['liveness'],
|
packages=['liveness'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
)
|
)
|
||||||
|
@ -116,7 +116,9 @@ class TestImports(unittest.TestCase):
|
|||||||
|
|
||||||
def test_args(self):
|
def test_args(self):
|
||||||
checks = ['tests.imports.import_args']
|
checks = ['tests.imports.import_args']
|
||||||
liveness.linux.load(checks, namespace=self.unit, rundir=self.run_dir, args=['foo'], kwargs={'bar': 42})
|
aargs=['foo']
|
||||||
|
kwaargs={'bar': 42}
|
||||||
|
liveness.linux.load(checks, self.unit, self.run_dir, *aargs, **kwaargs)
|
||||||
f = open(self.pid_path, 'r')
|
f = open(self.pid_path, 'r')
|
||||||
r = f.read()
|
r = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user