Skip to content

Commitment

solana.rpc.commitment

Commitment options.

Solana nodes choose which bank state to query based on a commitment requirement set by the client.

In descending order of commitment (most finalized to least finalized), clients may specify:

Commitment

Enumeration of commitment levels for RPC requests.

Members
Source code in src/solana/rpc/commitment.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Commitment(StrEnum):
    """Enumeration of commitment levels for RPC requests.

    Members:
        PROCESSED: The node will query its most recent block. Note that the block may not be complete.
        CONFIRMED: The node will query the most recent block that has been voted on by supermajority of the cluster.
        FINALIZED: The node will query the most recent block confirmed by supermajority of the cluster as finalized.
    """

    PROCESSED = "processed"
    """The node will query its most recent block. Note that the block may not be complete."""

    CONFIRMED = "confirmed"
    """The node will query the most recent block that has been voted on by supermajority of the cluster.

    - It incorporates votes from gossip and replay.
    - It does not count votes on descendants of a block, only direct votes on that block.
    - This confirmation level also upholds "optimistic confirmation" guarantees in release 1.3 and onwards.
    """

    FINALIZED = "finalized"
    """The node will query the most recent block confirmed by supermajority of the cluster as having reached maximum
    lockout, meaning the cluster has recognized this block as finalized."""

CONFIRMED = 'confirmed' class-attribute instance-attribute

The node will query the most recent block that has been voted on by supermajority of the cluster.

  • It incorporates votes from gossip and replay.
  • It does not count votes on descendants of a block, only direct votes on that block.
  • This confirmation level also upholds "optimistic confirmation" guarantees in release 1.3 and onwards.

FINALIZED = 'finalized' class-attribute instance-attribute

The node will query the most recent block confirmed by supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized.

PROCESSED = 'processed' class-attribute instance-attribute

The node will query its most recent block. Note that the block may not be complete.

commitment_comparator(a, b)

Compare two commitment levels by their degree of finalization.

Parameters:

Name Type Description Default
a Commitment

First commitment level.

required
b Commitment

Second commitment level.

required

Returns:

Type Description
Literal[-1, 0, 1]

-1 if a is less finalized than b, 0 if they are equal, 1 if a is more finalized than b.

Example

commitment_comparator(Commitment.FINALIZED, Commitment.PROCESSED) 1 commitment_comparator(Commitment.PROCESSED, Commitment.CONFIRMED) -1 commitment_comparator(Commitment.CONFIRMED, Commitment.CONFIRMED) 0

Source code in src/solana/rpc/commitment.py
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def commitment_comparator(a: Commitment, b: Commitment) -> Literal[-1, 0, 1]:
    """Compare two commitment levels by their degree of finalization.

    Args:
        a: First commitment level.
        b: Second commitment level.

    Returns:
        -1 if ``a`` is less finalized than ``b``,
            0 if they are equal,
            1 if ``a`` is more finalized than ``b``.

    Example:
        >>> commitment_comparator(Commitment.FINALIZED, Commitment.PROCESSED)
        1
        >>> commitment_comparator(Commitment.PROCESSED, Commitment.CONFIRMED)
        -1
        >>> commitment_comparator(Commitment.CONFIRMED, Commitment.CONFIRMED)
        0
    """
    if a is b:
        return 0
    return -1 if get_commitment_score(a) < get_commitment_score(b) else 1

get_commitment_score(commitment)

Return an integer score for a commitment level, with higher scores meaning more finalized.

Parameters:

Name Type Description Default
commitment Commitment

The commitment level to score.

required

Returns:

Type Description
int

An integer score (2 for FINALIZED, 1 for CONFIRMED, 0 for PROCESSED).

Example

get_commitment_score(Commitment.FINALIZED) 2 get_commitment_score(Commitment.CONFIRMED) 1 get_commitment_score(Commitment.PROCESSED) 0

Source code in src/solana/rpc/commitment.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def get_commitment_score(commitment: Commitment) -> int:
    """Return an integer score for a commitment level, with higher scores meaning more finalized.

    Args:
        commitment: The commitment level to score.

    Returns:
        An integer score (2 for FINALIZED, 1 for CONFIRMED, 0 for PROCESSED).

    Example:
        >>> get_commitment_score(Commitment.FINALIZED)
        2
        >>> get_commitment_score(Commitment.CONFIRMED)
        1
        >>> get_commitment_score(Commitment.PROCESSED)
        0
    """
    match commitment:
        case Commitment.FINALIZED:
            return 2
        case Commitment.CONFIRMED:
            return 1
        case Commitment.PROCESSED:
            return 0
        case _:
            assert_never(commitment)