Skip to content

Commit

Permalink
msgIdFn: use Buffer.subarray() (#4342)
Browse files Browse the repository at this point in the history
* msgIdFn: use Buffer.slice()

* Use Buffer.subarray() instead of Buffer.slice()
  • Loading branch information
twoeths authored Aug 1, 2022
1 parent 8bb7c66 commit 9979836
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/beacon-node/src/network/gossip/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {GossipTopicCache} from "./topic.js";
*/
export function fastMsgIdFn(rpcMsg: RPC.IMessage): string {
if (rpcMsg.data) {
return Buffer.from(digest(rpcMsg.data)).slice(0, 8).toString("hex");
return Buffer.from(digest(rpcMsg.data)).subarray(0, 8).toString("hex");
} else {
return "0000000000000000";
}
Expand Down Expand Up @@ -53,7 +53,7 @@ export function msgIdFn(gossipTopicCache: GossipTopicCache, msg: GossipsubMessag
}
}

return digest(Buffer.concat(vec)).slice(0, 20);
return Buffer.from(digest(Buffer.concat(vec))).subarray(0, 20);
}

export class DataTransformSnappy {
Expand Down
4 changes: 2 additions & 2 deletions packages/beacon-node/src/util/multifork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export function getSignedBlockTypeFromBytes(
}

export function getSlotFromBytes(bytes: Buffer | Uint8Array): Slot {
return bytesToInt(bytes.slice(SLOT_BYTES_POSITION_IN_BLOCK, SLOT_BYTES_POSITION_IN_BLOCK + SLOT_BYTE_COUNT));
return bytesToInt(bytes.subarray(SLOT_BYTES_POSITION_IN_BLOCK, SLOT_BYTES_POSITION_IN_BLOCK + SLOT_BYTE_COUNT));
}

export function getStateTypeFromBytes(
config: IChainForkConfig,
bytes: Buffer | Uint8Array
): allForks.AllForksSSZTypes["BeaconState"] {
const slot = bytesToInt(bytes.slice(SLOT_BYTES_POSITION_IN_STATE, SLOT_BYTES_POSITION_IN_STATE + SLOT_BYTE_COUNT));
const slot = bytesToInt(bytes.subarray(SLOT_BYTES_POSITION_IN_STATE, SLOT_BYTES_POSITION_IN_STATE + SLOT_BYTE_COUNT));
return config.getForkTypes(slot).BeaconState;
}

0 comments on commit 9979836

Please sign in to comment.