Skip to content

Commit

Permalink
Archival proofs (#204) (#205)
Browse files Browse the repository at this point in the history
* Added Archival proof types

* Moved Bucket types to remove circular dependency
  • Loading branch information
SirTyson authored Aug 14, 2024
1 parent e303b4c commit e16f824
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 69 deletions.
116 changes: 116 additions & 0 deletions Stellar-ledger-entries.x
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,119 @@ enum EnvelopeType
ENVELOPE_TYPE_SOROBAN_AUTHORIZATION = 9
};
}

enum BucketListType
{
LIVE = 0,
HOT_ARCHIVE = 1,
COLD_ARCHIVE = 2
};

/* Entries used to define the bucket list */
enum BucketEntryType
{
METAENTRY =
-1, // At-and-after protocol 11: bucket metadata, should come first.
LIVEENTRY = 0, // Before protocol 11: created-or-updated;
// At-and-after protocol 11: only updated.
DEADENTRY = 1,
INITENTRY = 2 // At-and-after protocol 11: only created.
};

enum HotArchiveBucketEntryType
{
HOT_ARCHIVE_METAENTRY = -1, // Bucket metadata, should come first.
HOT_ARCHIVE_ARCHIVED = 0, // Entry is Archived
HOT_ARCHIVE_LIVE = 1, // Entry was previously HOT_ARCHIVE_ARCHIVED, or HOT_ARCHIVE_DELETED, but
// has been added back to the live BucketList.
// Does not need to be persisted.
HOT_ARCHIVE_DELETED = 2 // Entry deleted (Note: must be persisted in archive)
};

enum ColdArchiveBucketEntryType
{
COLD_ARCHIVE_METAENTRY = -1, // Bucket metadata, should come first.
COLD_ARCHIVE_ARCHIVED_LEAF = 0, // Full LedgerEntry that was archived during the epoch
COLD_ARCHIVE_DELETED_LEAF = 1, // LedgerKey that was deleted during the epoch
COLD_ARCHIVE_BOUNDARY_LEAF = 2, // Dummy leaf representing low/high bound
COLD_ARCHIVE_HASH = 3 // Intermediary Merkle hash entry
};

struct BucketMetadata
{
// Indicates the protocol version used to create / merge this bucket.
uint32 ledgerVersion;

// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
BucketListType bucketListType;
}
ext;
};

union BucketEntry switch (BucketEntryType type)
{
case LIVEENTRY:
case INITENTRY:
LedgerEntry liveEntry;

case DEADENTRY:
LedgerKey deadEntry;
case METAENTRY:
BucketMetadata metaEntry;
};

union HotArchiveBucketEntry switch (HotArchiveBucketEntryType type)
{
case HOT_ARCHIVE_ARCHIVED:
LedgerEntry archivedEntry;

case HOT_ARCHIVE_LIVE:
case HOT_ARCHIVE_DELETED:
LedgerKey key;
case HOT_ARCHIVE_METAENTRY:
BucketMetadata metaEntry;
};

struct ColdArchiveArchivedLeaf
{
uint32 index;
LedgerEntry archivedEntry;
};

struct ColdArchiveDeletedLeaf
{
uint32 index;
LedgerKey deletedKey;
};

struct ColdArchiveBoundaryLeaf
{
uint32 index;
bool isLowerBound;
};

struct ColdArchiveHashEntry
{
uint32 index;
uint32 level;
Hash hash;
};

union ColdArchiveBucketEntry switch (ColdArchiveBucketEntryType type)
{
case COLD_ARCHIVE_METAENTRY:
BucketMetadata metaEntry;
case COLD_ARCHIVE_ARCHIVED_LEAF:
ColdArchiveArchivedLeaf archivedLeaf;
case COLD_ARCHIVE_DELETED_LEAF:
ColdArchiveDeletedLeaf deletedLeaf;
case COLD_ARCHIVE_BOUNDARY_LEAF:
ColdArchiveBoundaryLeaf boundaryLeaf;
case COLD_ARCHIVE_HASH:
ColdArchiveHashEntry hashEntry;
};
68 changes: 0 additions & 68 deletions Stellar-ledger.x
Original file line number Diff line number Diff line change
Expand Up @@ -157,74 +157,6 @@ struct ConfigUpgradeSet {
ConfigSettingEntry updatedEntry<>;
};

enum BucketListType
{
LIVE = 0,
HOT_ARCHIVE = 1,
COLD_ARCHIVE = 2
};

/* Entries used to define the bucket list */
enum BucketEntryType
{
METAENTRY =
-1, // At-and-after protocol 11: bucket metadata, should come first.
LIVEENTRY = 0, // Before protocol 11: created-or-updated;
// At-and-after protocol 11: only updated.
DEADENTRY = 1,
INITENTRY = 2 // At-and-after protocol 11: only created.
};

enum HotArchiveBucketEntryType
{
HOT_ARCHIVE_METAENTRY = -1, // Bucket metadata, should come first.
HOT_ARCHIVE_ARCHIVED = 0, // Entry is Archived
HOT_ARCHIVE_LIVE = 1, // Entry was previously HOT_ARCHIVE_ARCHIVED, or HOT_ARCHIVE_DELETED, but
// has been added back to the live BucketList.
// Does not need to be persisted.
HOT_ARCHIVE_DELETED = 2 // Entry deleted (Note: must be persisted in archive)
};

struct BucketMetadata
{
// Indicates the protocol version used to create / merge this bucket.
uint32 ledgerVersion;

// reserved for future use
union switch (int v)
{
case 0:
void;
case 1:
BucketListType bucketListType;
}
ext;
};

union BucketEntry switch (BucketEntryType type)
{
case LIVEENTRY:
case INITENTRY:
LedgerEntry liveEntry;

case DEADENTRY:
LedgerKey deadEntry;
case METAENTRY:
BucketMetadata metaEntry;
};

union HotArchiveBucketEntry switch (HotArchiveBucketEntryType type)
{
case HOT_ARCHIVE_ARCHIVED:
LedgerEntry archivedEntry;

case HOT_ARCHIVE_LIVE:
case HOT_ARCHIVE_DELETED:
LedgerKey key;
case HOT_ARCHIVE_METAENTRY:
BucketMetadata metaEntry;
};

enum TxSetComponentType
{
// txs with effective fee <= bid derived from a base fee (if any).
Expand Down
54 changes: 53 additions & 1 deletion Stellar-transaction.x
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,52 @@ struct LedgerFootprint
LedgerKey readWrite<>;
};

enum ArchivalProofType
{
EXISTENCE = 0,
NONEXISTENCE = 1
};

struct ArchivalProofNode
{
uint32 index;
Hash hash;
};

typedef ArchivalProofNode ProofLevel<>;

struct ArchivalProof
{
uint32 epoch; // AST Subtree for this proof

union switch (ArchivalProofType t)
{
case EXISTENCE:
struct
{
ColdArchiveBucketEntry entriesToProve<>;

// Vector of vectors, where proofLevels[level]
// contains all HashNodes that correspond with that level
ProofLevel proofLevels<>;
} existenceProof;
case NONEXISTENCE:
struct
{
LedgerKey keysToProve<>;

// Bounds for each key being proved, where bound[n]
// corresponds to keysToProve[n]
ColdArchiveBucketEntry lowBoundEntries<>;
ColdArchiveBucketEntry highBoundEntries<>;

// Vector of vectors, where proofLevels[level]
// contains all HashNodes that correspond with that level
ProofLevel proofLevels<>;
} nonexistenceProof;
} type;
};

// Resource limits for a Soroban transaction.
// The transaction will fail if it exceeds any of these limits.
struct SorobanResources
Expand All @@ -837,7 +883,13 @@ struct SorobanResources
// The transaction extension for Soroban.
struct SorobanTransactionData
{
ExtensionPoint ext;
union switch (int v)
{
case 0:
void;
case 1:
ArchivalProof proofs<>;
} ext;
SorobanResources resources;
// Amount of the transaction `fee` allocated to the Soroban resource fees.
// The fraction of `resourceFee` corresponding to `resources` specified
Expand Down

0 comments on commit e16f824

Please sign in to comment.