mycomesh-consumer 0.9.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mycomesh-consumer",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "MycoMesh V11 Consumer: a custodied deposit, relay-blind encrypted requests to any Provider, and a local OpenAI-compatible endpoint.",
5
5
  "repository": {
6
6
  "type": "git",
package/src/chain.mjs CHANGED
@@ -22,6 +22,17 @@ export async function rpcCall(urls, method, params, { timeoutMs = 15000 } = {})
22
22
 
23
23
  export const quantity = (value) => BigInt(value);
24
24
 
25
+ /** eth_getLogs that tolerates a load-balanced RPC answering from a node a block or two behind the head. */
26
+ export async function getLogs(urls, filter) {
27
+ try {
28
+ return await rpcCall(urls, "eth_getLogs", [filter]);
29
+ } catch (error) {
30
+ if (!/beyond current head/.test(error.message)) throw error;
31
+ const to = BigInt(filter.toBlock) - 3n;
32
+ return to < BigInt(filter.fromBlock) ? [] : rpcCall(urls, "eth_getLogs", [{ ...filter, toBlock: `0x${to.toString(16)}` }]);
33
+ }
34
+ }
35
+
25
36
  export async function ethCallWord(urls, to, data) {
26
37
  return BigInt(await rpcCall(urls, "eth_call", [{ to, data }, "latest"]));
27
38
  }
@@ -1,6 +1,6 @@
1
1
  // Provider ranking from what the chain and the probe ledger prove, not from what anyone claims.
2
2
  import { encodeCall, keccak, hex } from "./eip712.mjs";
3
- import { rpcCall } from "./chain.mjs";
3
+ import { getLogs, rpcCall } from "./chain.mjs";
4
4
  import { evidenceHash } from "./disputes.mjs";
5
5
  import { CAPABILITY_FLOORS, capabilityFlagged, verifyProbeEvidence } from "./probes.mjs";
6
6
 
@@ -32,8 +32,8 @@ async function ledgerEvents(network) {
32
32
  const events = [];
33
33
  for (let from = head > LOOKBACK_BLOCKS ? head - LOOKBACK_BLOCKS : 0n; from <= head; from += LOG_CHUNK) {
34
34
  const to = from + LOG_CHUNK - 1n < head ? from + LOG_CHUNK - 1n : head;
35
- for (const log of await rpcCall(network.rpc_urls, "eth_getLogs", [{ address: network.probe_ledger, topics: [PROBE_RECORDED],
36
- fromBlock: `0x${from.toString(16)}`, toBlock: `0x${to.toString(16)}` }])) {
35
+ for (const log of await getLogs(network.rpc_urls, { address: network.probe_ledger, topics: [PROBE_RECORDED],
36
+ fromBlock: `0x${from.toString(16)}`, toBlock: `0x${to.toString(16)}` })) {
37
37
  events.push({ provider: address(log.topics[1]), hunter: address(log.topics[2]), key: log.topics[3],
38
38
  evidence: `0x${log.data.slice(2, 66)}`, ...VERDICT_CODES[Number(BigInt(`0x${log.data.slice(66, 130)}`))] });
39
39
  }
package/src/rewards.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // MYCO rewards: every hour's fees mint MYCO for the Consumers who paid them (80%), their Providers (10%,
2
2
  // 48 hours later, by success rate), Relays (7%) and keepers (3%). Find, show and claim an account's share.
3
3
  import { encodeCall, encodeWords, hex, keccak } from "./eip712.mjs";
4
- import { rpcCall, sendTransaction } from "./chain.mjs";
4
+ import { getLogs, rpcCall, sendTransaction } from "./chain.mjs";
5
5
 
6
6
  export const ROLES = ["consumer", "provider", "relay", "bridge"];
7
7
  const POINTS = hex(keccak(new TextEncoder().encode("Points(uint64,uint8,address,uint256)")));
@@ -18,8 +18,8 @@ export async function earnedBlocks(network, account) {
18
18
  const topic = `0x${account.toLowerCase().replace(/^0x/, "").padStart(64, "0")}`;
19
19
  const found = new Map();
20
20
  for (let start = Number(network.emission_block || 0); start <= head; start += LOG_CHUNK) {
21
- const logs = await rpcCall(network.rpc_urls, "eth_getLogs", [{ address: network.emission, topics: [POINTS, null, null, topic],
22
- fromBlock: `0x${start.toString(16)}`, toBlock: `0x${Math.min(head, start + LOG_CHUNK - 1).toString(16)}` }]);
21
+ const logs = await getLogs(network.rpc_urls, { address: network.emission, topics: [POINTS, null, null, topic],
22
+ fromBlock: `0x${start.toString(16)}`, toBlock: `0x${Math.min(head, start + LOG_CHUNK - 1).toString(16)}` });
23
23
  for (const log of logs) {
24
24
  const role = Number(BigInt(log.topics[2]));
25
25
  if (!found.has(role)) found.set(role, new Set());