refactor(target_chains/ethereum): clean up unused batch update code

This commit is contained in:
Pavel Strakhov 2024-03-27 17:19:47 +00:00
parent 06965d38cc
commit 8843d0f875
8 changed files with 0 additions and 182 deletions

View File

@ -175,76 +175,6 @@ abstract contract Pyth is
if (price.publishTime == 0) revert PythErrors.PriceFeedNotFound();
}
function parseBatchAttestationHeader(
bytes memory encoded
)
internal
pure
returns (uint index, uint nAttestations, uint attestationSize)
{
unchecked {
index = 0;
// Check header
{
uint32 magic = UnsafeBytesLib.toUint32(encoded, index);
index += 4;
if (magic != 0x50325748) revert PythErrors.InvalidUpdateData();
uint16 versionMajor = UnsafeBytesLib.toUint16(encoded, index);
index += 2;
if (versionMajor != 3) revert PythErrors.InvalidUpdateData();
// This value is only used as the check below which currently
// never reverts
// uint16 versionMinor = UnsafeBytesLib.toUint16(encoded, index);
index += 2;
// This check is always false as versionMinor is 0, so it is commented.
// in the future that the minor version increases this will have effect.
// if(versionMinor < 0) revert InvalidUpdateData();
uint16 hdrSize = UnsafeBytesLib.toUint16(encoded, index);
index += 2;
// NOTE(2022-04-19): Currently, only payloadId comes after
// hdrSize. Future extra header fields must be read using a
// separate offset to respect hdrSize, i.e.:
//
// uint hdrIndex = 0;
// bpa.header.payloadId = UnsafeBytesLib.toUint8(encoded, index + hdrIndex);
// hdrIndex += 1;
//
// bpa.header.someNewField = UnsafeBytesLib.toUint32(encoded, index + hdrIndex);
// hdrIndex += 4;
//
// // Skip remaining unknown header bytes
// index += bpa.header.hdrSize;
uint8 payloadId = UnsafeBytesLib.toUint8(encoded, index);
// Skip remaining unknown header bytes
index += hdrSize;
// Payload ID of 2 required for batch headerBa
if (payloadId != 2) revert PythErrors.InvalidUpdateData();
}
// Parse the number of attestations
nAttestations = UnsafeBytesLib.toUint16(encoded, index);
index += 2;
// Parse the attestation size
attestationSize = UnsafeBytesLib.toUint16(encoded, index);
index += 2;
// Given the message is valid the arithmetic below should not overflow, and
// even if it overflows then the require would fail.
if (encoded.length != (index + (attestationSize * nAttestations)))
revert PythErrors.InvalidUpdateData();
}
}
function parsePriceFeedUpdatesInternal(
bytes[] calldata updateData,
bytes32[] calldata priceIds,

View File

@ -324,26 +324,6 @@ abstract contract PythTestUtils is Test, WormholeTestUtils, RandTestUtils {
);
}
// Generates a VAA for the given attestations.
// This method calls generatePriceFeedUpdatePayload and then creates a VAA with it.
// The VAAs generated from this method use block timestamp as their timestamp.
function generateWhBatchUpdate(
PriceAttestation[] memory attestations,
uint64 sequence,
uint8 numSigners
) public returns (bytes memory vaa) {
bytes memory payload = generatePriceFeedUpdatePayload(attestations);
vaa = generateVaa(
uint32(block.timestamp),
SOURCE_EMITTER_CHAIN_ID,
SOURCE_EMITTER_ADDRESS,
sequence,
payload,
numSigners
);
}
function pricesToPriceAttestations(
bytes32[] memory priceIds,
PythStructs.Price[] memory prices

View File

@ -15,9 +15,4 @@ interface IPythEvents {
int64 price,
uint64 conf
);
/// @dev Emitted when a batch price update is processed successfully.
/// @param chainId ID of the source chain that the batch price update comes from.
/// @param sequenceNumber Sequence number of the batch price update.
event BatchPriceFeedUpdate(uint16 chainId, uint64 sequenceNumber);
}

View File

@ -7,7 +7,6 @@ import "./PythErrors.sol";
contract MockPyth is AbstractPyth {
mapping(bytes32 => PythStructs.PriceFeed) priceFeeds;
uint64 sequenceNumber;
uint singleUpdateFeeInWei;
uint validTimePeriod;
@ -41,10 +40,6 @@ contract MockPyth is AbstractPyth {
uint requiredFee = getUpdateFee(updateData);
if (msg.value < requiredFee) revert PythErrors.InsufficientFee();
// Chain ID is id of the source chain that the price update comes from. Since it is just a mock contract
// We set it to 1.
uint16 chainId = 1;
for (uint i = 0; i < updateData.length; i++) {
PythStructs.PriceFeed memory priceFeed = abi.decode(
updateData[i],
@ -64,12 +59,6 @@ contract MockPyth is AbstractPyth {
);
}
}
// In the real contract, the input of this function contains multiple batches that each contain multiple prices.
// This event is emitted when a batch is processed. In this mock contract we consider there is only one batch of prices.
// Each batch has (chainId, sequenceNumber) as it's unique identifier. Here chainId is set to 1 and an increasing sequence number is used.
emit BatchPriceFeedUpdate(chainId, sequenceNumber);
sequenceNumber += 1;
}
function getUpdateFee(

View File

@ -14,25 +14,6 @@
"name": "StalePrice",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "chainId",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
}
],
"name": "BatchPriceFeedUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [

View File

@ -1,23 +1,4 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "chainId",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
}
],
"name": "BatchPriceFeedUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [

View File

@ -1,23 +1,4 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "chainId",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
}
],
"name": "BatchPriceFeedUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [

View File

@ -45,25 +45,6 @@
"name": "StalePrice",
"type": "error"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint16",
"name": "chainId",
"type": "uint16"
},
{
"indexed": false,
"internalType": "uint64",
"name": "sequenceNumber",
"type": "uint64"
}
],
"name": "BatchPriceFeedUpdate",
"type": "event"
},
{
"anonymous": false,
"inputs": [