Skip to content

Commit

Permalink
WIP yarn format
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-nikolov96 committed Sep 13, 2023
1 parent e21c3d6 commit 6176fd8
Show file tree
Hide file tree
Showing 9 changed files with 12,399 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getFilesInDir } from '../../../../libs/typescript/ts-utils/data';
import * as constants from '../../../../relay/constants/network_config.json';

export async function getProof(vkey, proof, originator, prevUpdate, update) {
const { ssz } = await import("@lodestar/types");
const { ssz } = await import('@lodestar/types');

let points: PointG1[] = prevUpdate.next_sync_committee.pubkeys.map(x =>
PointG1.fromHex(x.slice(2)),
Expand Down Expand Up @@ -157,8 +157,6 @@ export async function getProof(vkey, proof, originator, prevUpdate, update) {
return input;
}



(async () => {
const UPDATES = getFilesInDir(
path.join(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { writeFileSync, readFileSync, existsSync } from 'fs';
import { sleep } from '../../../libs/typescript/ts-utils/common-utils';

(async () => {
const { ssz } = await import('@lodestar/types');

let prevSlot = 0;

while (true) {
const beaconStateSZZ = await fetch(
`https://floral-chaotic-sea.discover.quiknode.pro/c1133f4fcc19bbe54fa6e4caf0c05ac79ec7d300/eth/v2/debug/beacon/states/head`,
{
headers: {
Accept: 'application/octet-stream',
},
},
)
.then(response => response.arrayBuffer())
.then(buffer => new Uint8Array(buffer));

const beaconState = ssz.capella.BeaconState.deserialize(beaconStateSZZ);

if (!existsSync('prev_beacon_state.ssz')) {
console.log('prev_beacon_state.ssz does not exist. Creating it.');

prevSlot = beaconState.slot;

writeFileSync(
'prev_beacon_state.ssz',
Buffer.from(beaconStateSZZ),
'binary',
);

await sleep(12000);
continue;
}

console.log(beaconState.slot);

if (prevSlot >= beaconState.slot) {
console.log('Waiting for the next epoch.');
await sleep(12000);
continue;
}

const prevBeaconStateSSZ = new Uint8Array(
readFileSync('prev_beacon_state.ssz'),
);

const prevBeaconState =
ssz.capella.BeaconState.deserialize(prevBeaconStateSSZ);

const balances = beaconState.balances;
const prevBalances = prevBeaconState.balances;

const balancesWithIndices = balances.map((balance, index) => ({
balance: balance,
index,
}));

const changedBalances = balancesWithIndices.filter(
({ balance, index }) =>
prevBalances[index] === undefined || balance !== prevBalances[index],
);

// TODO: push the changed validators to the tree

console.log('#changedBalances', changedBalances.length);

console.log(
'changed indices',
changedBalances.map(({ index }) => index),
);

writeFileSync(
'prev_beacon_state.ssz',
Buffer.from(beaconStateSZZ),
'binary',
);

prevSlot = beaconState.slot;

// wait for the next slot
await sleep(12000);
}
})();
8 changes: 8 additions & 0 deletions beacon-light-client/plonky2/circuits/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod hash_tree_root;
mod is_valid_merkle_branch;
mod utils;
mod validator_hash_tree_root;

fn main() {
println!("Hello, world!");
}
Loading

0 comments on commit 6176fd8

Please sign in to comment.