Ejemplo n.º 1
0
def run(steps=4000):
    n = networksim.NetworkSimulator(latency=NETWORK_LATENCY)
    for i in range(NUM_VALIDATORS):
        n.agents.append(Validator(i, n))
    n.generate_peers(3)
    while len(all_signatures):
        all_signatures.pop()
    for x in future.keys():
        del future[x]
    for x in finalized_blocks.keys():
        del finalized_blocks[x]
    for x in discarded.keys():
        del discarded[x]
    for i in range(steps):
        n.tick()
        if i % 500 == 0:
            minmax = 99999999999999999
            for x in n.agents:
                minmax = min(minmax, x.max_finalized_height - 10)
            print get_opinions(n)[max(minmax, 0):]
            finalized0 = [(v.max_finalized_height, v.finalized_hashes)
                          for v in n.agents]
            if CHECK_INTEGRITY:
                finalized = sorted(finalized0, key=lambda x: len(x[1]))
                for j in range(len(n.agents) - 1):
                    for k in range(len(finalized[j][1])):
                        if finalized[j][1][k] is not None and finalized[
                                j + 1][1][k] is not None:
                            if finalized[j][1][k] != finalized[j + 1][1][k]:
                                print finalized[j]
                                print finalized[j + 1]
                                raise Exception(
                                    "Finalization mismatch: %r %r" %
                                    (finalized[j][1][k],
                                     finalized[j + 1][1][k]))
            print 'Finalized status: %r' % [x[0] for x in finalized0]
            _all = finalized0[0][1]
            _pos = len([x for x in _all if x])
            _neg = len([x for x in _all if not x])
            print 'Finalized blocks: %r (%r positive, %r negaitve)' % (
                len(_all), _pos, _neg)
        if i == 10000 and NETSPLITS >= 1:
            print "###########################################################"
            print "Knocking off 20% of the network!!!!!"
            print "###########################################################"
            n.knock_offline_random(NUM_VALIDATORS // 5)
        if i == 20000 and NETSPLITS >= 2:
            print "###########################################################"
            print "Simluating a netsplit!!!!!"
            print "###########################################################"
            n.generate_peers()
            n.partition()
        if i == 30000 and NETSPLITS >= 1:
            print "###########################################################"
            print "Network health back to normal!"
            print "###########################################################"
            n.generate_peers()
    calibrate(n.agents[0].finalized_hashes[:n.agents[0].max_finalized_height +
                                           1])
Ejemplo n.º 2
0
def run(steps=10):
    n = networksim.NetworkSimulator()

    # XXX: Not clear to me what's best here
    # Interactive: less BW, Batch: less coordination
    a = Node("A", n, 'burstyMobile', 'batch')
    b = Node("B", n, 'burstyMobile', 'batch')
    c = Node("C", n, 'desktop', 'interactive')
    d = Node("D", n, 'desktop', 'batch')

    n.peers["A"] = a
    n.peers["B"] = b
    n.peers["C"] = c
    n.peers["D"] = d
    n.nodes = [a, b, c, d]

    a.addPeer("B", b)
    a.addPeer("C", c)
    b.addPeer("A", a)
    c.addPeer("A", a)

    #b.addPeer("C", c) # hm
    #c.addPeer("B", b)

    b.addPeer("D", d)
    c.addPeer("D", d)

    # NOTE: Client should decide policy, implict group
    a.share("B")
    b.share("A")

    # C and D participating
    # a.share("C")
    b.share("D")
    c.share("A")
    c.share("D")
    d.share("B")
    d.share("C")

    print("\nAssuming one group context (A-B (C-D) share):")

    # XXX: Conditional append to get message graph?
    # TODO: Actually need to encode graph, client concern
    local_appends = {
        1: [[a, "A: hello world"]],
        2: [[b, "B: hello!"]],
    }

    for i in range(steps):
        # NOTE: include signature and parent message
        if n.time in local_appends:
            for peer, msg in local_appends[n.time]:
                rec = new_message_record(msg)
                peer.append_message(rec)

        n.tick()
Ejemplo n.º 3
0
Archivo: test.py Proyecto: yep/research
from ethereum.parse_genesis_declaration import mk_basic_state
from ethereum.config import Env
from ethereum.casper_utils import RandaoManager, generate_validation_code, call_casper, \
    get_skips_and_block_making_time, sign_block, get_contract_code, \
    casper_config, get_casper_ct, get_casper_code, get_rlp_decoder_code, \
    get_hash_without_ed_code, make_casper_genesis
from ethereum.utils import sha3, privtoaddr
from ethereum.transactions import Transaction
from ethereum.state_transition import apply_transaction

from ethereum.slogging import LogRecorder, configure_logging, set_level
# config_string = ':info,eth.vm.log:trace,eth.vm.op:trace,eth.vm.stack:trace,eth.vm.exit:trace,eth.pb.msg:trace,eth.pb.tx:debug'
config_string = ':info,eth.vm.log:trace'
configure_logging(config_string=config_string)

n = networksim.NetworkSimulator(latency=150)
n.time = 2
print 'Generating keys'
keys = [sha3(str(i)) for i in range(20)]
print 'Initializing randaos'
randaos = [RandaoManager(sha3(k)) for k in keys]
deposit_sizes = [128] * 15 + [256] * 5

print 'Creating genesis state'
s = make_casper_genesis(
    validators=[(generate_validation_code(privtoaddr(k)), ds * 10**18,
                 r.get(9999))
                for k, ds, r in zip(keys, deposit_sizes, randaos)],
    alloc={privtoaddr(k): {
        'balance': 10**18
    }