@@ -56,7 +56,7 @@ abstract contract Pulse is IPulse, PulseState {
5656 // TODO: there can be a separate wrapper function that defaults the provider (or uses the cheapest or something).
5757 function requestPriceUpdatesWithCallback (
5858 address provider ,
59- uint256 publishTime ,
59+ uint64 publishTime ,
6060 bytes32 [] calldata priceIds ,
6161 uint256 callbackGasLimit
6262 ) external payable override returns (uint64 requestSequenceNumber ) {
@@ -65,7 +65,7 @@ abstract contract Pulse is IPulse, PulseState {
6565 "Provider not registered "
6666 );
6767
68- // FIXME: this comment is wrong.
68+ // FIXME: this comment is wrong. (we're not using tx.gasprice)
6969 // NOTE: The 60-second future limit on publishTime prevents a DoS vector where
7070 // attackers could submit many low-fee requests for far-future updates when gas prices
7171 // are low, forcing executors to fulfill them later when gas prices might be much higher.
@@ -93,7 +93,6 @@ abstract contract Pulse is IPulse, PulseState {
9393 for (uint8 i = 0 ; i < priceIds.length ; i++ ) {
9494 req.priceIds[i] = priceIds[i];
9595 }
96-
9796 _state.accruedFeesInWei += _state.pythFeeInWei;
9897
9998 emit PriceUpdateRequested (req, priceIds);
@@ -129,7 +128,6 @@ abstract contract Pulse is IPulse, PulseState {
129128 }
130129 }
131130
132- // Parse price feeds first to measure gas usage
133131 // TODO: should this use parsePriceFeedUpdatesUnique? also, do we need to add 1 to maxPublishTime?
134132 IPyth pyth = IPyth (_state.pyth);
135133 uint256 pythFee = pyth.getUpdateFee (updateData);
@@ -142,7 +140,6 @@ abstract contract Pulse is IPulse, PulseState {
142140 SafeCast.toUint64 (req.publishTime)
143141 );
144142
145- clearRequest (sequenceNumber);
146143 // TODO: if this effect occurs here, we need to guarantee that executeCallback can never revert.
147144 // If executeCallback can revert, then funds can be permanently locked in the contract.
148145 // TODO: there also needs to be some penalty mechanism in case the expected provider doesn't execute the callback.
@@ -153,6 +150,18 @@ abstract contract Pulse is IPulse, PulseState {
153150 _state.providers[providerToCredit].accruedFeesInWei += SafeCast
154151 .toUint128 (msg .value - pythFee);
155152
153+ clearRequest (sequenceNumber);
154+
155+ // TODO: I'm pretty sure this is going to use a lot of gas because it's doing a storage lookup for each sequence number.
156+ // a better solution would be a doubly-linked list of active requests.
157+ // After successful callback, update firstUnfulfilledSeq if needed
158+ while (
159+ _state.firstUnfulfilledSeq < _state.currentSequenceNumber &&
160+ ! isActive (findRequest (_state.firstUnfulfilledSeq))
161+ ) {
162+ _state.firstUnfulfilledSeq++ ;
163+ }
164+
156165 try
157166 IPulseConsumer (req.requester)._pulseCallback {
158167 gas: req.callbackGasLimit
@@ -164,7 +173,7 @@ abstract contract Pulse is IPulse, PulseState {
164173 // Explicit revert/require
165174 emit PriceUpdateCallbackFailed (
166175 sequenceNumber,
167- msg . sender ,
176+ providerToCredit ,
168177 priceIds,
169178 req.requester,
170179 reason
@@ -173,21 +182,12 @@ abstract contract Pulse is IPulse, PulseState {
173182 // Out of gas or other low-level errors
174183 emit PriceUpdateCallbackFailed (
175184 sequenceNumber,
176- msg . sender ,
185+ providerToCredit ,
177186 priceIds,
178187 req.requester,
179188 "low-level error (possibly out of gas) "
180189 );
181190 }
182-
183- // TODO: I'm pretty sure this is going to use a lot of gas because it's doing a storage lookup for each sequence number.
184- // After successful callback, update firstUnfulfilledSeq if needed
185- while (
186- _state.firstUnfulfilledSeq < _state.currentSequenceNumber &&
187- ! isActive (findRequest (_state.firstUnfulfilledSeq))
188- ) {
189- _state.firstUnfulfilledSeq++ ;
190- }
191191 }
192192
193193 function emitPriceUpdate (
@@ -198,7 +198,7 @@ abstract contract Pulse is IPulse, PulseState {
198198 int64 [] memory prices = new int64 [](priceFeeds.length );
199199 uint64 [] memory conf = new uint64 [](priceFeeds.length );
200200 int32 [] memory expos = new int32 [](priceFeeds.length );
201- uint256 [] memory publishTimes = new uint256 [](priceFeeds.length );
201+ uint64 [] memory publishTimes = new uint256 [](priceFeeds.length );
202202
203203 for (uint i = 0 ; i < priceFeeds.length ; i++ ) {
204204 prices[i] = priceFeeds[i].price.price;
0 commit comments