Skip to content

Instantly share code, notes, and snippets.

View mgraczyk's full-sized avatar

Michael Graczyk mgraczyk

View GitHub Profile
func (n *Node) IsStronglyPreferred(tx *Transaction) bool {
mutex.RLock()
defer mutex.RUnlock()
stronglyPreferred := true
parents := // ... make map of parent ids
for len(parents) != 0 {
for parentId := range parents {
// [OT] stronglyPreferred could be memoized here for efficiency
// This is a downside of using protocol buffers for state.
// Additional in-memory state can't be stored naturally because
func QueryEvents(n *Node, rpc RPC) {
// [OT] Line 2 with modified condition
for id, tx := range n.Unqueried() {
// [OT] Check that the transactions parents are known
// In a real implementation, undigestible txns
// would eventually need to be pruned.
if !n.IsDigestable(tx) {
continue
}
// [OT] Lines 4-5
// ... update the preference for ancestors
// [OT] This only loops over parents, not ancestors
for _, parentId := range tx.Body.Parents {
mutex.RLock()
parent := n.Transactions[parentId]
conflicts := n.Conflicts[parent.Body.Utxo]
mutex.RUnlock()
parentScore, presentScore := n.Confidence(parent), n.Confidence(conflicts.Preferred)
if parentScore > presentScore {
conflicts.Preferred = parent
func (n *Node) IsAccepted(tx *Transaction) bool {
mutex.RLock()
defer mutex.RUnlock()
committed := false
for _, parent := range tx.Body.GetParents() {
parent := n.Transactions[parent]
committed = committed && n.IsAccepted(parent)
}
set := n.Conflicts[tx.Body.Utxo]
// [OT] safe early commitment.
@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)
import asyncio
num_times = 0
async def one_time_setup():
global num_times
num_times += 1
print("doing setup")
await asyncio.sleep(1)
import numpy as np
from matplotlib import pyplot as plt
def make_Av(N):
a = 1 - 0.5 * 0.75
b = 0.5 * 0.25
A = np.zeros((2 * N + 2, 2 * N + 2))
@mgraczyk
mgraczyk / leveldb_cat.py
Created June 22, 2021 04:18
leveldb_cat
#!/bin/env python3
import sys
try:
import plyvel
except ImportError:
print("Install plyvel: python3 -m pip install plyvel")
sys.exit(1)
def usage():
@mgraczyk
mgraczyk / liquidum_pool_1.sol
Last active July 1, 2021 02:57
liquidum_pool_1
// DO NOT USE: Incomplete example code.
contract PlotNFT is Ownable {
address target;
uint256 targetMinBlock;
constructor(address _target) public {
target = _target;
targetMinBlock = 0;
}

Keybase proof

I hereby claim:

  • I am mgraczyk on github.
  • I am mgraczyk (https://keybase.io/mgraczyk) on keybase.
  • I have a public key ASCXHJBSlHw5mSW5e3DkRc5b3u0lrX_rLTER3xi26FZoLgo

To claim this, I am signing this object: