コード例 #1
0
TARGET_PORT = BASE_PORT + 2 * 10

supervisor = UnixStreamXMLRPCClient('data/supervisor.sock')
rpc = RPC(BASE_PORT)

# wait for 3 validators online
print('Wait for 3 validators online')
wait_for_validators(rpc, 3)

enckey = rpc.wallet.restore(TARGET_NODE_MNEMONIC, name='target')

print('Stop', TARGET_NODE)
stop_node(supervisor, TARGET_NODE)

print('Waiting for', MISSED_BLOCK_THRESHOLD + 3, 'blocks')
wait_for_blocks(rpc, MISSED_BLOCK_THRESHOLD + 3)

assert len(rpc.chain.validators()['validators']) == 2

addr = rpc.address.list(enckey=enckey, name='target')[0]
state = rpc.staking.state(addr)
punishment = state['last_slash']
print('punishment', punishment)
assert punishment['kind'] == 'NonLive'
print('slash amount', punishment['amount'])

print('Starting', TARGET_NODE)
supervisor.supervisor.startProcessGroup(TARGET_NODE)
wait_for_port(TARGET_PORT + 9)
print('Started', TARGET_NODE)
コード例 #2
0
- check validators 3
'''

# keep these values same as jail_cluster.json
TARGET_NODE = 'node2'
TARGET_NODE_MNEMONIC = 'symptom labor zone shrug chicken bargain hood define tornado mass inquiry rural step color guitar'
TARGET_NODE_VALIDATOR_SEED = '5c1b9c06ae7485cd0f9d75819f964db3b1306ebd397f5bbdc1dd386a32b7c1c0'
MISSED_BLOCK_THRESHOLD = 5
JAIL_DURATION = 10
BASE_PORT = int(os.environ.get('BASE_PORT', 26650))
TARGET_PORT = BASE_PORT + 2 * 10

supervisor = UnixStreamXMLRPCClient('data/supervisor.sock')
rpc = get_rpc()
# wait for at least one block generated
wait_for_blocks(rpc, 1, height=0)

# wait for 3 validators online
print('Wait for 3 validators online')
wait_for_validators(rpc, 3)

enckey = rpc.wallet.restore(TARGET_NODE_MNEMONIC, name='target')

print('Stop', TARGET_NODE)
stop_node(supervisor, TARGET_NODE)

print('Waiting for', MISSED_BLOCK_THRESHOLD + 3, 'blocks')
wait_for_blocks(rpc, MISSED_BLOCK_THRESHOLD + 3)

assert len(rpc.chain.validators()['validators']) == 2
コード例 #3
0
ファイル: byzantine_test.py プロジェクト: stjordanis/chain
wait_for_validators(rpc, 1)

enckey = rpc.wallet.enckey()
os.environ['ENCKEY'] = enckey
bonded_staking, unbonded_staking = rpc.address.list()[:2]
transfer = rpc.address.list(type='transfer')[0]

txid = rpc.staking.withdraw_all_unbonded(unbonded_staking, transfer)
wait_for_tx(rpc, txid)
rpc.wallet.sync()

txid = rpc.staking.deposit(bonded_staking, [{'id': txid, 'index': 0}])
wait_for_tx(rpc, txid)
rpc.wallet.sync()

wait_for_blocks(rpc, 3)

print('Join node0')
txid = rpc.staking.join(
    'node0',
    SigningKey(VALIDATOR_SEED).pub_key_base64(),
    bonded_staking,
    rpc.staking.gen_keypackage(),
)

wait_for_tx(rpc, txid)

wait_for_blocks(rpc, 3)
assert len(rpc.chain.validators()['validators']) == 2

# start node1
コード例 #4
0
ファイル: byzantine_test.py プロジェクト: lezzokafka/thaler
- 3 nodes
- node2 has more than 2/3 voting powers
- node0 and node1 have same validator seed, both have 0 bonded coins initially, only unbonded coins.
- start the nodes, and stop node1 immediately.
- withdraw, deposit and join node0.
- start node1, check node0 punished with byzantine fault.
'''

# keep these values same as jail_cluster.json
VALIDATOR_SEED = '3d96c3c476e463bdcd751c9bf1715b7da37229ac00be33f34496797ca892b68a'

BASE_PORT = int(os.environ.get('BASE_PORT', 26650))
supervisor = UnixStreamXMLRPCClient('data/supervisor.sock')
rpc = get_rpc()
# wait for at least one block generated
wait_for_blocks(rpc, 1, height=0)

# stop node1
print('Stop node1')
stop_node(supervisor, 'node1')

print('Wait for 1 validators online')
wait_for_validators(rpc, 1)

enckey = rpc.wallet.enckey()
os.environ['ENCKEY'] = enckey
bonded_staking, unbonded_staking = rpc.address.list()[:2]
transfer = rpc.address.list(type='transfer')[0]

txid = rpc.staking.withdraw_all_unbonded(unbonded_staking, transfer)
wait_for_tx(rpc, txid)
コード例 #5
0
    period = 10
    Y = 365 * 24 * 60 * 60
    R = 0.45 * math.exp(-S / tau)
    N = int(S * (math.pow(1 + R, period / Y) - 1))
    return N - N % 10000


BASE_PORT = int(os.environ.get('BASE_PORT', 26650))
supervisor = UnixStreamXMLRPCClient('data/supervisor.sock')
wait_for_port(BASE_PORT + 20 + 7)

rpc = get_rpc()
rpc2 = get_rpc(2)
init_bonded = 90000000000000000

wait_for_blocks(rpc, 2, height=0)

os.environ['ENCKEY'] = rpc.wallet.enckey()
bonded_staking = rpc.address.list()[0]

# first reward distribution
# minted = 6978080000
minted = monetary_expansion(init_bonded * 2, 145000000000000000)

state = rpc.chain.staking(bonded_staking, height=2)
assert int(state['bonded']) == init_bonded + minted // 2

enckey2 = rpc2.wallet.enckey()
bonded_staking2 = rpc2.address.list(enckey=enckey2)[0]

state = rpc.chain.staking(bonded_staking2, height=2)