Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65f7f1d

Browse files
f: smaller contract size via proxy
1 parent 7ba3dd1 commit 65f7f1d

File tree

14 files changed

+256
-126
lines changed

14 files changed

+256
-126
lines changed

‎packages/horizon/contracts/data-service/utilities/ProvisionManager.sol

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ abstract contract ProvisionManager is Initializable, GraphDirectory, ProvisionMa
111111
_;
112112
}
113113

114+
modifier onlyAuthorizedForProvisionHack(address caller, address serviceProvider) {
115+
require(
116+
_graphStaking().isAuthorized(serviceProvider, address(this), caller),
117+
ProvisionManagerNotAuthorized(serviceProvider, caller)
118+
);
119+
_;
120+
}
121+
114122
/**
115123
* @notice Checks if a provision of a service provider is valid according
116124
* to the parameter ranges established.

‎packages/subgraph-service/contracts/DisputeManager.sol

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { IGraphToken } from "@graphprotocol/contracts/contracts/token/IGraphToke
55
import { IHorizonStaking } from "@graphprotocol/horizon/contracts/interfaces/IHorizonStaking.sol";
66
import { IDisputeManager } from "./interfaces/IDisputeManager.sol";
77
import { ISubgraphService } from "./interfaces/ISubgraphService.sol";
8+
import { ISubgraphServiceExtension } from "./interfaces/ISubgraphServiceExtension.sol";
89

910
import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
1011
import { TokenUtils } from "@graphprotocol/contracts/contracts/utils/TokenUtils.sol";
@@ -480,7 +481,9 @@ contract DisputeManager is
480481
bytes32 _poi,
481482
uint256 _entities
482483
) private returns (bytes32) {
483-
IndexingAgreement.AgreementWrapper memory wrapper = _getSubgraphService().getIndexingAgreement(_agreementId);
484+
IndexingAgreement.AgreementWrapper memory wrapper = _getSubgraphServiceExtension().getIndexingAgreement(
485+
_agreementId
486+
);
484487

485488
// Agreement must have been collected on and be a version 1
486489
require(
@@ -703,6 +706,16 @@ contract DisputeManager is
703706
return subgraphService;
704707
}
705708

709+
/**
710+
* @notice Get the address of the subgraph service extension
711+
* @dev Will revert if the subgraph service is not set
712+
* @return The subgraph service address
713+
*/
714+
function _getSubgraphServiceExtension() private view returns (ISubgraphServiceExtension) {
715+
require(address(subgraphService) != address(0), DisputeManagerSubgraphServiceNotSet());
716+
return ISubgraphServiceExtension(address(subgraphService));
717+
}
718+
706719
/**
707720
* @notice Returns whether the dispute is for a conflicting attestation or not.
708721
* @param _dispute Dispute

‎packages/subgraph-service/contracts/SubgraphService.sol

Lines changed: 50 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ contract SubgraphService is
7575
address disputeManager,
7676
address graphTallyCollector,
7777
address curation,
78-
address recurringCollector
78+
address recurringCollector,
79+
address extension
7980
)
8081
DataService(graphController)
81-
Directory(address(this), disputeManager, graphTallyCollector, curation, recurringCollector)
82+
Directory(address(this), disputeManager, graphTallyCollector, curation, recurringCollector, extension)
8283
{
8384
_disableInitializers();
8485
}
@@ -553,6 +554,10 @@ contract SubgraphService is
553554
emit StakeToFeesRatioSet(_stakeToFeesRatio);
554555
}
555556

557+
function _cancelAllocationIndexingAgreement(address _allocationId) internal {
558+
_indexingAgreementManager().cancelForAllocation(_allocationId);
559+
}
560+
556561
/**
557562
* @notice Accept an indexing agreement.
558563
* See {ISubgraphService.acceptIndexingAgreement}.
@@ -584,75 +589,7 @@ contract SubgraphService is
584589
onlyValidProvision(signedRCA.rca.serviceProvider)
585590
onlyRegisteredIndexer(signedRCA.rca.serviceProvider)
586591
{
587-
_indexingAgreementManager.accept(_allocations, allocationId, signedRCA);
588-
}
589-
590-
function upgradeIndexingAgreement(
591-
address indexer,
592-
IRecurringCollector.SignedRCAU calldata signedRCAU
593-
)
594-
external
595-
whenNotPaused
596-
onlyAuthorizedForProvision(indexer)
597-
onlyValidProvision(indexer)
598-
onlyRegisteredIndexer(indexer)
599-
{
600-
_indexingAgreementManager.upgrade(indexer, signedRCAU);
601-
}
602-
603-
/**
604-
* @notice Cancel an indexing agreement by indexer / operator.
605-
* See {ISubgraphService.cancelIndexingAgreement}.
606-
*
607-
* @dev Can only be canceled on behalf of a valid indexer.
608-
*
609-
* Requirements:
610-
* - The indexer must be registered
611-
* - The caller must be authorized by the indexer
612-
* - The provision must be valid according to the subgraph service rules
613-
* - The agreement must be active
614-
*
615-
* Emits {IndexingAgreementCanceled} event
616-
*
617-
* @param agreementId The id of the agreement
618-
*/
619-
function cancelIndexingAgreement(
620-
address indexer,
621-
bytes16 agreementId
622-
)
623-
external
624-
whenNotPaused
625-
onlyAuthorizedForProvision(indexer)
626-
onlyValidProvision(indexer)
627-
onlyRegisteredIndexer(indexer)
628-
{
629-
_indexingAgreementManager.cancel(indexer, agreementId);
630-
}
631-
632-
function _cancelAllocationIndexingAgreement(address _allocationId) internal {
633-
_indexingAgreementManager.cancelForAllocation(_allocationId);
634-
}
635-
636-
/**
637-
* @notice Cancel an indexing agreement by payer / signer.
638-
* See {ISubgraphService.cancelIndexingAgreementByPayer}.
639-
*
640-
* Requirements:
641-
* - The caller must be authorized by the payer
642-
* - The agreement must be active
643-
*
644-
* Emits {IndexingAgreementCanceled} event
645-
*
646-
* @param agreementId The id of the agreement
647-
*/
648-
function cancelIndexingAgreementByPayer(bytes16 agreementId) external whenNotPaused {
649-
_indexingAgreementManager.cancelByPayer(agreementId);
650-
}
651-
652-
function getIndexingAgreement(
653-
bytes16 agreementId
654-
) external view returns (IndexingAgreement.AgreementWrapper memory) {
655-
return _indexingAgreementManager.get(agreementId);
592+
_indexingAgreementManager().accept(_allocations, allocationId, signedRCA);
656593
}
657594

658595
/**
@@ -680,7 +617,7 @@ contract SubgraphService is
680617
* @return The amount of fees collected
681618
*/
682619
function _collectIndexingFees(bytes16 _agreementId, bytes memory _data) private returns (uint256) {
683-
(address indexer, uint256 tokensCollected) = _indexingAgreementManager.collect(
620+
(address indexer, uint256 tokensCollected) = _indexingAgreementManager().collect(
684621
_allocations,
685622
_agreementId,
686623
_data
@@ -702,4 +639,45 @@ contract SubgraphService is
702639
);
703640
}
704641
}
642+
643+
function modifiersHack(
644+
address caller,
645+
address indexer
646+
)
647+
external
648+
view
649+
whenNotPaused
650+
onlyAuthorizedForProvisionHack(caller, indexer)
651+
onlyValidProvision(indexer)
652+
onlyRegisteredIndexer(indexer)
653+
{}
654+
655+
/**
656+
* @notice Delegates the call to the SubgraphServiceExtension implementation.
657+
* @dev This function does not return to its internal call site, it will return directly to the
658+
* external caller.
659+
*/
660+
// solhint-disable-next-line payable-fallback, no-complex-fallback
661+
fallback() external {
662+
address extImpl = _subgraphServiceExtensionImpl();
663+
require(extImpl != address(0), "only through proxy");
664+
665+
// solhint-disable-next-line no-inline-assembly
666+
assembly {
667+
// copy function selector and any arguments
668+
calldatacopy(0, 0, calldatasize())
669+
// execute function call using the extension implementation
670+
let result := delegatecall(gas(), extImpl, 0, calldatasize(), 0, 0)
671+
// get any return value
672+
returndatacopy(0, 0, returndatasize())
673+
// return any return value or error back to the caller
674+
switch result
675+
case 0 {
676+
revert(0, returndatasize())
677+
}
678+
default {
679+
return(0, returndatasize())
680+
}
681+
}
682+
}
705683
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.8.27;
3+
4+
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/PausableUpgradeable.sol";
5+
import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol";
6+
7+
import { IndexingAgreementManagerStorageV1 } from "./utilities/IndexingAgreementManagerStorageV1.sol";
8+
import { IndexingAgreement } from "./libraries/IndexingAgreement.sol";
9+
import { SubgraphService } from "./SubgraphService.sol";
10+
11+
contract SubgraphServiceExtension is PausableUpgradeable, IndexingAgreementManagerStorageV1 {
12+
using IndexingAgreement for IndexingAgreement.Manager;
13+
14+
modifier modifiersHack(address indexer) {
15+
SubgraphService(address(this)).modifiersHack(msg.sender, indexer);
16+
_;
17+
}
18+
19+
function upgradeIndexingAgreement(
20+
address indexer,
21+
IRecurringCollector.SignedRCAU calldata signedRCAU
22+
) external modifiersHack(indexer) {
23+
_indexingAgreementManager().upgrade(indexer, signedRCAU);
24+
}
25+
26+
/**
27+
* @notice Cancel an indexing agreement by indexer / operator.
28+
* See {ISubgraphService.cancelIndexingAgreement}.
29+
*
30+
* @dev Can only be canceled on behalf of a valid indexer.
31+
*
32+
* Requirements:
33+
* - The indexer must be registered
34+
* - The caller must be authorized by the indexer
35+
* - The provision must be valid according to the subgraph service rules
36+
* - The agreement must be active
37+
*
38+
* Emits {IndexingAgreementCanceled} event
39+
*
40+
* @param agreementId The id of the agreement
41+
*/
42+
function cancelIndexingAgreement(address indexer, bytes16 agreementId) external modifiersHack(indexer) {
43+
_indexingAgreementManager().cancel(indexer, agreementId);
44+
}
45+
46+
/**
47+
* @notice Cancel an indexing agreement by payer / signer.
48+
* See {ISubgraphService.cancelIndexingAgreementByPayer}.
49+
*
50+
* Requirements:
51+
* - The caller must be authorized by the payer
52+
* - The agreement must be active
53+
*
54+
* Emits {IndexingAgreementCanceled} event
55+
*
56+
* @param agreementId The id of the agreement
57+
*/
58+
function cancelIndexingAgreementByPayer(bytes16 agreementId) external whenNotPaused {
59+
_indexingAgreementManager().cancelByPayer(agreementId);
60+
}
61+
62+
function getIndexingAgreement(
63+
bytes16 agreementId
64+
) external view returns (IndexingAgreement.AgreementWrapper memory) {
65+
return _indexingAgreementManager().get(agreementId);
66+
}
67+
68+
function _cancelAllocationIndexingAgreement(address _allocationId) internal {
69+
_indexingAgreementManager().cancelForAllocation(_allocationId);
70+
}
71+
}

‎packages/subgraph-service/contracts/interfaces/ISubgraphService.sol

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ pragma solidity 0.8.27;
33

44
import { IDataServiceFees } from "@graphprotocol/horizon/contracts/data-service/interfaces/IDataServiceFees.sol";
55
import { IGraphPayments } from "@graphprotocol/horizon/contracts/interfaces/IGraphPayments.sol";
6-
import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol";
76

87
import { Allocation } from "../libraries/Allocation.sol";
98
import { LegacyAllocation } from "../libraries/LegacyAllocation.sol";
10-
import { IndexingAgreement } from "../libraries/IndexingAgreement.sol";
9+
10+
import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol";
1111

1212
/**
1313
* @title Interface for the {SubgraphService} contract
@@ -301,23 +301,4 @@ interface ISubgraphService is IDataServiceFees {
301301
* @notice Accept an indexing agreement.
302302
*/
303303
function acceptIndexingAgreement(address allocationId, IRecurringCollector.SignedRCA calldata signedRCA) external;
304-
305-
/**
306-
* @notice Upgrade an indexing agreement.
307-
*/
308-
function upgradeIndexingAgreement(address indexer, IRecurringCollector.SignedRCAU calldata signedRCAU) external;
309-
310-
/**
311-
* @notice Cancel an indexing agreement by indexer / operator.
312-
*/
313-
function cancelIndexingAgreement(address indexer, bytes16 agreementId) external;
314-
315-
/**
316-
* @notice Cancel an indexing agreement by payer / signer.
317-
*/
318-
function cancelIndexingAgreementByPayer(bytes16 agreementId) external;
319-
320-
function getIndexingAgreement(
321-
bytes16 agreementId
322-
) external view returns (IndexingAgreement.AgreementWrapper memory);
323304
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
pragma solidity 0.8.27;
3+
4+
import { IRecurringCollector } from "@graphprotocol/horizon/contracts/interfaces/IRecurringCollector.sol";
5+
6+
import { IndexingAgreement } from "../libraries/IndexingAgreement.sol";
7+
8+
interface ISubgraphServiceExtension {
9+
/**
10+
* @notice Accept an indexing agreement.
11+
*/
12+
// function acceptIndexingAgreement(address allocationId, IRecurringCollector.SignedRCA calldata signedRCA) external;
13+
14+
/**
15+
* @notice Upgrade an indexing agreement.
16+
*/
17+
function upgradeIndexingAgreement(address indexer, IRecurringCollector.SignedRCAU calldata signedRCAU) external;
18+
19+
/**
20+
* @notice Cancel an indexing agreement by indexer / operator.
21+
*/
22+
function cancelIndexingAgreement(address indexer, bytes16 agreementId) external;
23+
24+
/**
25+
* @notice Cancel an indexing agreement by payer / signer.
26+
*/
27+
function cancelIndexingAgreementByPayer(bytes16 agreementId) external;
28+
29+
function getIndexingAgreement(
30+
bytes16 agreementId
31+
) external view returns (IndexingAgreement.AgreementWrapper memory);
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /