Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ATX versioning #5774

Open
fasmat opened this issue Mar 25, 2024 · 0 comments
Open

Introduce ATX versioning #5774

fasmat opened this issue Mar 25, 2024 · 0 comments
Assignees

Comments

@fasmat
Copy link
Member

fasmat commented Mar 25, 2024

Motivation

This is the first step in allowing extensions to activation transactions in the go-spacemesh protocol.

Description

To allow adding additional data and removing redundancy from Activation Transactions (ATXs) for upcoming features, we need to introduce an ATX versioning scheme that allows new versions of ATXs in a non-backwards compatible way.

The current ActivationTx in

// ActivationTx is a full, signed activation transaction. It includes (or references) everything a miner needs to prove
// they are eligible to actively participate in the Spacemesh protocol in the next epoch.
type ActivationTx struct {
InnerActivationTx
SmesherID NodeID
Signature EdSignature
golden bool
}
needs to be retired in serving dual purpose as a) encoding an ATX going over the wire and b) as representation of an ATX in services that need it.

Instead it needs to be split in a type that is uses solely to be encoded with go-scale to be sent over the wire during sync and gossip and a type that is used in services and as a representation of the data stored in the state database.

Additionally the ATX ID needs to be changed for v2 to allow more efficient encoding of Malfeasance proofs. For this the ID needs to be set to the root of a binary tree that is formed from the fields of the ATX (or their hashes). This way a malfeasance proof only needs the ATX ID and the relevant fields for the proof, the rest can be represented by the hashes of branches with fields that are not relevant for the proof, which should make Malfeasance proofs smaller and more flexible than they are at at the moment.

Acceptance criteria

  • ActivationTx is reduced to the following domain type:
type ActivationTx struct {
	ID                 types.ATXID
	PrevATX            types.ATXID
	// PosATX            types.ATXID // unsure if needed, only add to domain type if helpful in some place
	Node               types.NodeID
	Coinbase           types.Address
	NumUnits           uint32 // represents "effective numunits"
	NumTicks           uint64
	BaseHeight         uint64
	Nonce              types.VRFPostIndex
	Malicious          bool
}

func (a ActivationTx) Weight() uint64 {
	return a.NumUnits*a.NumTicks
}

func (a ActivationTx) Height() uint64 {
	return a.BaseHeight+a.NumTicks
}
  • The algorithm for calculating the ATXID in v2 ATXs is changed from concatenating the publication epoch to the hash of the go-scale encoded ATX to instead using the root of a tree comprised of the fields of the ATX (or their respective hashes).
  • The wire types for ATXs can be defined in the activation package, while the domain type will probably need to stay in the common/types package. No package besides the activation package should encode or decode wire types.
    • This means that sql packages need to store all domain relevant fields as columns in the atxs table in the DB and must not encode or decode the binary ATX blob, which is still stored and can be fetched for things linke checkpoint and sync but packages accessing the ATX blob should treat them as opaque and pass them along to functions like the activation.Handler which does the decoding and validation.
    • Other packages needing access to an ATX should use the domain type which is reduced to only relevant fields (as below)
    • The atxsdata.ATX type should be removed again and replaced by the new domain type which replaces its purpose.

## Implementation hints

- For ATXID calculation the `merkle-tree` implementation in https://github.com/spacemeshos/merkle-tree that is used for PoET can probably be re-used.
@fasmat fasmat changed the title WiP: Introduce ATX versioning Introduce ATX versioning Apr 15, 2024
spacemesh-bors bot pushed a commit that referenced this issue Apr 15, 2024
…5784)

## Motivation
Part of #5774

Split ActivationTx into:
- a type used for encoding and signing, serialized into blobs and sent "over the wire" (`package wire`),
- a type meant for use in the rest of the code (`package types`) - this is not serialized anywhere and is free to change at any time.
spacemesh-bors bot pushed a commit that referenced this issue Apr 15, 2024
…5784)

## Motivation
Part of #5774

Split ActivationTx into:
- a type used for encoding and signing, serialized into blobs and sent "over the wire" (`package wire`),
- a type meant for use in the rest of the code (`package types`) - this is not serialized anywhere and is free to change at any time.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🏗 Doing
Development

No branches or pull requests

2 participants