Skip to content

Instantly share code, notes, and snippets.

View mgraczyk's full-sized avatar

Michael Graczyk mgraczyk

View GitHub Profile
@mgraczyk
mgraczyk / fix_keras_model.py
Last active August 29, 2019 07:46
Fix input_dtype errors in pre-2.0 keras model H5FS files
# Usage: fix_keras_model.py old_model.h5 new_model.h5
import h5py
import shutil
import json
import sys
input_model_path = sys.argv[1]
output_model_path = sys.argv[2]
shutil.copyfile(input_model_path, output_model_path)
547dce2f801f943423638c89e9b90a0f2c1ea8b9
1e7c40a1ca01421d56cdb9ef0ee6534aca1cdd58
import numpy as np
import sys
from random import randint
from math import ceil
def run_simulation(N, sims):
threshold = int(0.5 + 2. * N / 3)
print('{} / {}'.format(threshold, N))
results = []
@mgraczyk
mgraczyk / event_loop.go
Created June 27, 2018 20:42
Perlin Avalanche Code Review
func (state *NodeActor) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
// [OT] ... Other cases for starting, stopping
case *messages.QueryRequest:
response := &messages.QueryResponse{}
if msg.Transaction != nil && msg.Transaction.Verify() {
stronglyPreferred := state.node.OnQueryTx(msg.Transaction)
response.Transaction = msg.Transaction.Id
message Node {
map<string, Transaction> queried = 1;
map<string, Transaction> transactions = 2;
map<uint64, ConflictSet> conflicts = 3;
map<string, uint64> chits = 4;
}
func (state *NodeActor) Receive(ctx actor.Context) {
switch msg := ctx.Message().(type) {
// ... Other cases for starting, stopping
case *messages.QueryRequest:
// ...
case *messages.ApiReceiveTransaction:
// ...
}
// [OT] This case corresponds to onGenerateTx in the paper.
case *messages.ApiReceiveTransaction:
// [OT] small race, should be `utxo := atomic.Add...() - 1`
// already being fixed by Perlin
utxo := atomic.LoadUint64(&messages.LastUTXO)
atomic.AddUint64(&messages.LastUTXO, 1)
body := messages.CreateTx(utxo, store.GetKeys().PublicKeyHex(), state.node.SelectParents(), msg.Data)
state.node.OnReceiveTx(body.Sign(store.GetKeys()))
// Searches for suitable parent transactions for a new transaction.
func (n *Node) SelectParents() []string {
// [OT] The lock could be held for less time with BFS
mutex.RLock()
defer mutex.RUnlock()
var eligibleParents []*Transaction
// [OT] Search every historical transaction.
for _, tx := range n.Transactions {
if n.IsStronglyPreferred(tx) {
// [OT] Figure 19, line 2
case *messages.QueryRequest:
response := &messages.QueryResponse{}
if msg.Transaction != nil && msg.Transaction.Verify() {
stronglyPreferred := state.node.OnQueryTx(msg.Transaction)
response.Transaction = msg.Transaction.Id
response.StronglyPreferred = stronglyPreferred
ctx.Respond(response)
}
// [OT] Always respond with empty? Does this overwrite?
ctx.Respond(response)