Skip to content

Commit

Permalink
Merge branch 'master' into eosio-buyram-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
moskvanaft committed May 25, 2018
2 parents bd21625 + ac5b4f3 commit f034af3
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 78 deletions.
12 changes: 11 additions & 1 deletion contracts/eosio.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ namespace eosiosystem {
for ( auto it = idx.cbegin(); it != idx.cend() && top_producers.size() < 21 && 0 < it->total_votes; ++it ) {
if( !it->active() ) continue;

if ( it->time_became_active.slot == 0 ) {
/**
If it's the first time or it's been over a day since a producer was last voted in,
update his info. Otherwise, a producer gets a grace period of 7 hours after which
he gets deactivated if he hasn't produced in 24 hours.
*/
if ( it->time_became_active.slot == 0 ||
block_time.slot > it->time_became_active.slot + blocks_per_day ) {
_producers.modify( *it, 0, [&](auto& p) {
p.time_became_active = block_time;
});
Expand All @@ -92,6 +98,10 @@ namespace eosiosystem {
});

continue;
} else {
_producers.modify( *it, 0, [&](auto& p) {
p.time_became_active = block_time;
});
}

top_producers.emplace_back( std::pair<eosio::producer_key,uint16_t>({{it->owner, it->producer_key}, it->location}));
Expand Down
26 changes: 13 additions & 13 deletions plugins/txn_test_gen_plugin/txn_test_gen_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct txn_test_gen_plugin_impl {
void create_test_accounts(const std::string& init_name, const std::string& init_priv_key) {
name newaccountA("txn.test.a");
name newaccountB("txn.test.b");
name newaccountC("eosio.token");
name newaccountC("txn.test.t");
name creator(init_name);

abi_def currency_abi_def = fc::json::from_string(eosio_token_abi).as<abi_def>();
Expand Down Expand Up @@ -109,7 +109,7 @@ struct txn_test_gen_plugin_impl {

trx.actions.emplace_back(vector<chain::permission_level>{{creator,"active"}}, newaccount{creator, newaccountB, owner_auth, active_auth});
}
//create "eosio.token" account
//create "txn.test.t" account
{
auto owner_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};
auto active_auth = eosio::chain::authority{1, {{txn_text_receiver_C_pub_key, 1}}, {}};
Expand All @@ -123,7 +123,7 @@ struct txn_test_gen_plugin_impl {
push_transaction(trx);
}

//set eosio.token contract & initialize it
//set txn.test.t contract to eosio.token & initialize it
{
signed_transaction trx;

Expand All @@ -144,34 +144,34 @@ struct txn_test_gen_plugin_impl {

{
action act;
act.account = N(eosio.token);
act.account = N(txn.test.t);
act.name = N(create);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"eosio.token\",\"maximum_supply\":\"1000000000.0000 CUR\"}}"));
act.data = eosio_token_serializer.variant_to_binary("create", fc::json::from_string("{\"issuer\":\"txn.test.t\",\"maximum_supply\":\"1000000000.0000 CUR\"}}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(eosio.token);
act.account = N(txn.test.t);
act.name = N(issue);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"eosio.token\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("issue", fc::json::from_string("{\"to\":\"txn.test.t\",\"quantity\":\"600.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(eosio.token);
act.account = N(txn.test.t);
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.a\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}
{
action act;
act.account = N(eosio.token);
act.account = N(txn.test.t);
act.name = N(transfer);
act.authorization = vector<permission_level>{{newaccountC,config::active_name}};
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"eosio.token\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
act.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string("{\"from\":\"txn.test.t\",\"to\":\"txn.test.b\",\"quantity\":\"200.0000 CUR\",\"memo\":\"\"}"));
trx.actions.push_back(act);
}

Expand All @@ -196,12 +196,12 @@ struct txn_test_gen_plugin_impl {
running = true;

//create the actions here
act_a_to_b.account = N(eosio.token);
act_a_to_b.account = N(txn.test.t);
act_a_to_b.name = N(transfer);
act_a_to_b.authorization = vector<permission_level>{{name("txn.test.a"),config::active_name}};
act_a_to_b.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.a\",\"to\":\"txn.test.b\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));

act_b_to_a.account = N(eosio.token);
act_b_to_a.account = N(txn.test.t);
act_b_to_a.name = N(transfer);
act_b_to_a.authorization = vector<permission_level>{{name("txn.test.b"),config::active_name}};
act_b_to_a.data = eosio_token_serializer.variant_to_binary("transfer", fc::json::from_string(fc::format_string("{\"from\":\"txn.test.b\",\"to\":\"txn.test.a\",\"quantity\":\"1.0000 CUR\",\"memo\":\"${l}\"}", fc::mutable_variant_object()("l", salt))));
Expand Down
168 changes: 114 additions & 54 deletions tutorials/bios-boot-tutorial/bios-boot-tutorial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

import argparse
import json
import numpy
import os
Expand All @@ -14,14 +15,14 @@
unlockTimeout = 99999999999
nodesDir = './nodes/'
contractsDir = '../../build/contracts/'
cleos = 'cleos --wallet-url http://localhost:6666 --url http://localhost:8000 '
cleos = 'cleos --wallet-url http://localhost:6666 '
nodeos = 'nodeos'
fastUnstakeSystem = './fast.refund/eosio.system/eosio.system.wasm'
logFile = open('test.log', 'a')

symbol = 'SYS'
maxUserKeys = 10 # Maximum user keys to import into wallet
minProducerStake = 20.0000 # Minimum producer CPU and BW stake
minProducerStake = 200.0000 # Minimum producer CPU and BW stake
extraIssue = 10.0000 # Extra amount to issue to cover buying ram
limitUsers = 0 # Limit number of users if >0
limitProducers = 0 # Limit number of producers if >0
Expand Down Expand Up @@ -60,34 +61,34 @@ def jsonArg(a):
return " '" + json.dumps(a) + "' "

def run(args):
print('test.py:', args)
print('bios-boot-tutorial.py:', args)
logFile.write(args + '\n')
if subprocess.call(args, shell=True):
print('test.py: exiting because of error')
print('bios-boot-tutorial.py: exiting because of error')
sys.exit(1)

def retry(args):
while True:
print('test.py:', args)
print('bios-boot-tutorial.py:', args)
logFile.write(args + '\n')
if subprocess.call(args, shell=True):
print('*** Retry')
else:
break

def background(args):
print('test.py:', args)
print('bios-boot-tutorial.py:', args)
logFile.write(args + '\n')
return subprocess.Popen(args, shell=True)

def getOutput(args):
print('test.py:', args)
print('bios-boot-tutorial.py:', args)
logFile.write(args + '\n')
proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE)
return proc.communicate()[0].decode('utf-8')

def getJsonOutput(args):
print('test.py:', args)
print('bios-boot-tutorial.py:', args)
logFile.write(args + '\n')
proc = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE)
return json.loads(proc.communicate()[0])
Expand Down Expand Up @@ -201,9 +202,11 @@ def vote(b, e):

def claimRewards():
table = getJsonOutput(cleos + 'get table eosio eosio producers -l 100')
times = []
for row in table['rows']:
if row['unpaid_blocks'] and not row['last_claim_time']:
run(cleos + 'system claimrewards ' + row['owner'])
times.append(getJsonOutput(cleos + 'system claimrewards -j ' + row['owner'])['processed']['elapsed'])
print('Elapsed time for claimrewards:', times)

def vote(b, e):
for i in range(b, e):
Expand Down Expand Up @@ -246,15 +249,13 @@ def sendUnstakedFunds(b, e):
a = accounts[i]
run(cleos + 'transfer eosio ' + a['name'] + ' "10.0000 ' + symbol + '"')

def randomTransfer(b, e, n):
for i in range(n):
for j in range(20):
src = accounts[random.randint(b, e - 1)]['name']
dest = src
while dest == src:
dest = accounts[random.randint(b, e - 1)]['name']
run(cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + symbol + '"' + ' || true')
sleep(.25)
def randomTransfer(b, e):
for j in range(20):
src = accounts[random.randint(b, e - 1)]['name']
dest = src
while dest == src:
dest = accounts[random.randint(b, e - 1)]['name']
run(cleos + 'transfer -f ' + src + ' ' + dest + ' "0.0001 ' + symbol + '"' + ' || true')

def msigProposeReplaceSystem(proposer, proposalName):
requestedPermissions = []
Expand Down Expand Up @@ -295,39 +296,98 @@ def produceNewAccounts():
f.write(' {"name":"%s", "pvt":"%s", "pub":"%s"},\n' % (name, r[1], r[2]))

logFile.write('\n\n' + '*' * 80 + '\n\n\n')
run('killall keosd nodeos || true')
sleep(1.5)
startWallet()
importKeys()
startNode(0, {'name': 'eosio', 'pvt': eosioPvt, 'pub': eosioPub})
sleep(1.5)
createSystemAccounts()
run(cleos + 'set contract eosio.token ' + contractsDir + 'eosio.token/')
run(cleos + 'set contract eosio.msig ' + contractsDir + 'eosio.msig/')
run(cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (symbol))
totalAllocation = fillStake(0, len(accounts))
run(cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation))
sleep(1)
retry(cleos + 'set contract eosio ' + contractsDir + 'eosio.system/')
sleep(1)
run(cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active')
createStakedAccounts(0, len(accounts))
regProducers(firstProducer, firstProducer + numProducers)
sleep(1)
listProducers()
startProducers(firstProducer, firstProducer + numProducers)
sleep(producerSyncDelay)
vote(0, 0 + numVoters)
sleep(1)
listProducers()
sleep(5)
claimRewards()
proxyVotes(0, 0 + numVoters)
resign('eosio', 'eosio.prods')
for a in systemAccounts:
resign(a, 'eosio')
# msigReplaceSystem()
run(cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, symbol))
sendUnstakedFunds(0, numSenders)
randomTransfer(0, numSenders, 8)
run('tail -n 60 ' + nodesDir + '00-eosio/stderr')

def stepKillAll():
run('killall keosd nodeos || true')
sleep(1.5)
def stepStartWallet():
startWallet()
importKeys()
def stepStartBoot():
startNode(0, {'name': 'eosio', 'pvt': eosioPvt, 'pub': eosioPub})
sleep(1.5)
def stepInstallSystemContracts():
run(cleos + 'set contract eosio.token ' + contractsDir + 'eosio.token/')
run(cleos + 'set contract eosio.msig ' + contractsDir + 'eosio.msig/')
def stepCreateTokens():
run(cleos + 'push action eosio.token create \'["eosio", "10000000000.0000 %s"]\' -p eosio.token' % (symbol))
totalAllocation = fillStake(0, len(accounts))
run(cleos + 'push action eosio.token issue \'["eosio", "%s", "memo"]\' -p eosio' % intToCurrency(totalAllocation))
sleep(1)
def stepSetSystemContract():
retry(cleos + 'set contract eosio ' + contractsDir + 'eosio.system/')
sleep(1)
run(cleos + 'push action eosio setpriv' + jsonArg(['eosio.msig', 1]) + '-p eosio@active')
def stepCreateStakedAccounts():
createStakedAccounts(0, len(accounts))
def stepRegProducers():
regProducers(firstProducer, firstProducer + numProducers)
sleep(1)
listProducers()
def stepStartProducers():
startProducers(firstProducer, firstProducer + numProducers)
sleep(producerSyncDelay)
def stepVote():
vote(0, 0 + numVoters)
sleep(1)
listProducers()
sleep(5)
def stepProxyVotes():
proxyVotes(0, 0 + numVoters)
def stepResign():
resign('eosio', 'eosio.prods')
for a in systemAccounts:
resign(a, 'eosio')
def stepIssueUnstaked():
run(cleos + 'push action eosio.token issue \'["eosio", "%d.0000 %s", "memo"]\' -p eosio' % ((len(accounts)) * 10, symbol))
sendUnstakedFunds(0, numSenders)
def stepTransfer():
while True:
randomTransfer(0, numSenders)
def stepLog():
run('tail -n 60 ' + nodesDir + '00-eosio/stderr')

commands = [
('k', 'kill', stepKillAll, True, "Kill all nodeos and keosd processes"),
('w', 'wallet', stepStartWallet, True, "Start keosd, create wallet, fill with keys"),
('b', 'boot', stepStartBoot, True, "Start boot node"),
('s', 'sys', createSystemAccounts, True, "Create system accounts (eosio.*)"),
('c', 'contracts', stepInstallSystemContracts, True, "Install system contracts (token, msig)"),
('t', 'tokens', stepCreateTokens, True, "Create tokens"),
('S', 'sys-contract', stepSetSystemContract, True, "Set system contract"),
('T', 'stake', stepCreateStakedAccounts, True, "Create staked accounts"),
('p', 'reg-prod', stepRegProducers, True, "Register producers"),
('P', 'start-prod', stepStartProducers, True, "Start producers"),
('v', 'vote', stepVote, True, "Vote for producers"),
('R', 'claim', claimRewards, True, "Claim rewards"),
('x', 'proxy', stepProxyVotes, True, "Proxy votes"),
('q', 'resign', stepResign, True, "Resign eosio"),
('m', 'msg-replace', msigReplaceSystem, False, "Replace system contract using msig"),
('u', 'issue', stepIssueUnstaked, True, "Issue unstaked tokens"),
('X', 'xfer', stepTransfer, False, "Random transfer tokens (infinite loop)"),
('l', 'log', stepLog, True, "Show tail of node's log"),
]

parser = argparse.ArgumentParser()
parser.add_argument('-a', '--all', action='store_true', help="Do everything marked with (*)")
parser.add_argument('-H', '--http-port', type=int, default=8000, help='Http port for cleos')
for (flag, command, function, inAll, help) in commands:
prefix = ''
if inAll: prefix += '*'
if prefix: help = '(' + prefix + ') ' + help
if flag:
parser.add_argument('-' + flag, '--' + command, action='store_true', help=help, dest=command)
else:
parser.add_argument('--' + command, action='store_true', help=help, dest=command)
args = parser.parse_args()

cleos += '--url http://localhost:%d ' % args.http_port

haveCommand = False
for (flag, command, function, inAll, help) in commands:
if getattr(args, command) or inAll and args.all:
if function:
haveCommand = True
function()
if not haveCommand:
print('bios-boot-tutorial.py: Tell me what to do. -a does almost everything. -h shows options.')
Loading

0 comments on commit f034af3

Please sign in to comment.