Added logging

This commit is contained in:
vub 2017-04-03 00:57:00 -04:00
parent e4ee923c93
commit 8094cb1a8a
2 changed files with 13 additions and 2 deletions

View File

@ -91,6 +91,12 @@ reward_at_1m_eth: decimal
# Have I already been initialized? # Have I already been initialized?
initialized: bool initialized: bool
# Log topic for prepare
prepare_log_topic: bytes32
# Log topic for commit
commit_log_topic: bytes32
def initiate(): def initiate():
assert not self.initialized assert not self.initialized
self.initialized = True self.initialized = True
@ -118,7 +124,7 @@ def initiate():
# Initialize the epoch counter # Initialize the epoch counter
self.current_epoch = block.number / self.epoch_length self.current_epoch = block.number / self.epoch_length
# Set the sighash calculator address # Set the sighash calculator address
self.sighasher = 0x476c2ca9a7f3b16feca86512276271faf63b6a24 self.sighasher = 0x476c2cA9a7f3B16FeCa86512276271FAf63B6a24
# Set an initial root of the epoch hash chain # Set an initial root of the epoch hash chain
self.consensus_messages[0].ancestry_hash_justified[0x0000000000000000000000000000000000000000000000000000000000000000] = True self.consensus_messages[0].ancestry_hash_justified[0x0000000000000000000000000000000000000000000000000000000000000000] = True
# Set initial total deposit counter # Set initial total deposit counter
@ -127,6 +133,9 @@ def initiate():
self.consensus_messages[0].deposit_scale_factor = 1000000000000000000.0 self.consensus_messages[0].deposit_scale_factor = 1000000000000000000.0
# Total ETH given out assuming 1m ETH deposits # Total ETH given out assuming 1m ETH deposits
self.reward_at_1m_eth = 12.5 self.reward_at_1m_eth = 12.5
# Log topics for prepare and commit
self.prepare_log_topic = sha3("prepare()")
self.commit_log_topic = sha3("commit()")
# Called at the start of any epoch # Called at the start of any epoch
def initialize_epoch(epoch: num): def initialize_epoch(epoch: num):
@ -300,6 +309,7 @@ def prepare(validator_index: num, prepare_msg: bytes <= 1024):
self.consensus_messages[epoch].hash_justified[hash] = True self.consensus_messages[epoch].hash_justified[hash] = True
# Add a parent-child relation between ancestry hashes to the ancestry table # Add a parent-child relation between ancestry hashes to the ancestry table
self.ancestry[ancestry_hash][new_ancestry_hash] = 1 self.ancestry[ancestry_hash][new_ancestry_hash] = 1
raw_log([self.prepare_log_topic], prepare_msg)
# Process a commit message # Process a commit message
def commit(validator_index: num, commit_msg: bytes <= 1024): def commit(validator_index: num, commit_msg: bytes <= 1024):
@ -348,6 +358,7 @@ def commit(validator_index: num, commit_msg: bytes <= 1024):
self.consensus_messages[epoch].prev_dyn_commits[hash] >= self.total_deposits[self.dynasty - 1] * 2 / 3) and \ self.consensus_messages[epoch].prev_dyn_commits[hash] >= self.total_deposits[self.dynasty - 1] * 2 / 3) and \
not self.consensus_messages[epoch].committed: not self.consensus_messages[epoch].committed:
self.consensus_messages[epoch].committed = True self.consensus_messages[epoch].committed = True
raw_log([self.commit_log_topic], commit_msg)
# Cannot make two prepares in the same epoch # Cannot make two prepares in the same epoch
def double_prepare_slash(validator_index: num, prepare1: bytes <= 1000, prepare2: bytes <= 1000): def double_prepare_slash(validator_index: num, prepare1: bytes <= 1000, prepare2: bytes <= 1000):

View File

@ -25,7 +25,7 @@ assert s.state.get_code('0x476c2ca9a7f3b16feca86512276271faf63b6a24')
# Install Casper # Install Casper
casper_code = open('simple_casper.v.py').read().replace('0x1db3439a222c519ab44bb1144fc28167b4fa6ee6', '0x'+utils.encode_hex(t.a0)) casper_code = open('simple_casper.v.py').read().replace('0x1db3439a222c519ab44bb1144fc28167b4fa6ee6', utils.checksum_encode(t.a0))
print('Casper code length', len(compiler.compile(casper_code))) print('Casper code length', len(compiler.compile(casper_code)))