encapsulate core storage maps via private visibility

Signed-off-by: Uncle Fatso <uncle.fatso@ghostchain.io>
This commit is contained in:
Uncle Fatso 2026-09-26 17:20:16 +03:00
parent 3f4e6ff8f5
commit b87dff4c7a
Signed by: f4ts0
GPG Key ID: 565F4F2860226EBB
2 changed files with 42 additions and 10 deletions

View File

@ -17,10 +17,10 @@ abstract contract Weaver is IWeaver {
uint256 public override currentWeavingSession; uint256 public override currentWeavingSession;
uint256 public override startWeavingSession; uint256 public override startWeavingSession;
mapping(uint256 => mapping(uint256 => Checkpoints.Trace256)) internal _treeNodes; mapping(uint256 => mapping(uint256 => Checkpoints.Trace256)) private _treeNodes;
mapping(uint256 => mapping(uint256 => Checkpoints.Trace160)) internal _slotLenghts; mapping(uint256 => mapping(uint256 => Checkpoints.Trace160)) private _slotLenghts;
mapping(uint256 => mapping(uint256 => bytes32[])) internal _slotValues; mapping(uint256 => mapping(uint256 => bytes32[])) private _slotValues;
mapping(uint256 => uint256) internal _filledEntries; mapping(uint256 => uint256) private _filledEntries;
function previousAddress() external virtual view returns (address); function previousAddress() external virtual view returns (address);
@ -178,4 +178,36 @@ abstract contract Weaver is IWeaver {
currentWeavingSession = newSession; currentWeavingSession = newSession;
startWeavingSession = newSession; startWeavingSession = newSession;
} }
function _getTreeNodesLatest(uint256 session, uint256 index) internal view returns (uint256) {
return _treeNodes[session][index].latest();
}
function _getTreeNodesUpperLookup(
uint256 session,
uint256 index,
uint256 atBlock
) internal view returns (uint256) {
return _treeNodes[session][index].upperLookup(atBlock);
}
function _getSlotLenghtsLatest(uint256 session, uint256 index) internal view returns (uint160) {
return _slotLenghts[session][index].latest();
}
function _getSlotLenghtsUpperLookup(
uint256 session,
uint256 index,
uint96 atBlock
) internal view returns (uint160) {
return _slotLenghts[session][index].upperLookup(atBlock);
}
function _getSlotValue(uint256 session, uint256 slot, uint256 index) internal view returns (bytes32) {
return _slotValues[session][slot][index];
}
function _getFilledEntries(uint256 session) internal view returns (uint256) {
return _filledEntries[session];
}
} }

View File

@ -46,23 +46,23 @@ contract GatekeeperWeaver is Gatekeeper {
constructor(address storageHistory, address staking) Gatekeeper(storageHistory, staking) {} constructor(address storageHistory, address staking) Gatekeeper(storageHistory, staking) {}
function filledEntries(uint256 session) public view returns (uint256) { function filledEntries(uint256 session) public view returns (uint256) {
return _filledEntries[session]; return _getFilledEntries(session);
} }
function slotLengths(uint256 session, uint256 globalIndex) public view returns (uint160) { function slotLengths(uint256 session, uint256 globalIndex) public view returns (uint160) {
uint256 slotIndex = globalIndex % SLOTS; uint256 slotIndex = globalIndex % SLOTS;
return _slotLenghts[session][slotIndex].latest(); return _getSlotLenghtsLatest(session, slotIndex);
} }
function slotValues(uint256 session, uint256 globalIndex) public view returns (bytes32) { function slotValue(uint256 session, uint256 globalIndex) public view returns (bytes32) {
uint256 slotIndex = globalIndex % SLOTS; uint256 slotIndex = globalIndex % SLOTS;
uint256 valueIndex = globalIndex / SLOTS; uint256 valueIndex = globalIndex / SLOTS;
return _slotValues[session][slotIndex][valueIndex]; return _getSlotValue(session, slotIndex, valueIndex);
} }
function treeNodesLatest(uint256 session, uint256 globalIndex) public view returns (bytes32) { function treeNodesLatest(uint256 session, uint256 globalIndex) public view returns (bytes32) {
uint256 slotIndex = globalIndex % SLOTS; uint256 slotIndex = globalIndex % SLOTS;
return bytes32(_treeNodes[session][slotIndex].latest()); return bytes32(_getTreeNodesLatest(session, slotIndex));
} }
function computePreimage(uint256 globalIndex, uint256 a, bytes32 r) public view returns (bytes32) { function computePreimage(uint256 globalIndex, uint256 a, bytes32 r) public view returns (bytes32) {
@ -242,7 +242,7 @@ contract GatekeeperWeaverTest is Test {
} }
{ {
bytes32 preimage1 = gatekeeper.slotValues(emittedSession, globalIndex); bytes32 preimage1 = gatekeeper.slotValue(emittedSession, globalIndex);
bytes32 preimage2 = gatekeeper.computePreimage(globalIndex, amount, who); bytes32 preimage2 = gatekeeper.computePreimage(globalIndex, amount, who);
assertEq(preimage1, preimage2); assertEq(preimage1, preimage2);
} }