Finding the shard that covers a TON account after a split
A block collector cached a shard assignment yesterday. Today a parent shard has split. Account routing depends on a prefix of the account ID and the shard layout at the height under investigation.
Match the account ID against the observed layout
Assume one workchain with the three illustrative active prefixes below. An account ID beginning with byte a0 starts in binary with 10, so it belongs to the second shard in that layout. The example uses plain prefix bits, not the wire encoding of a shard identifier.
const active = ["0", "10", "11"];
for (const firstByte of [0x20, 0xa0, 0xe1]) {
const bits = firstByte.toString(2).padStart(8, "0");
console.log(bits, active.find(prefix => bits.startsWith(prefix)));
}
Anchor historical queries to the old layout
Read the shard configuration associated with the relevant masterchain block. If a previous layout had children 0 and 1, that same account matched 1 before the split. Store workchain, shard identifier and block reference together when recording the result. The friendly address string includes formatting and network flags; take prefix bits from the decoded account ID, not from its printed text.