Skip to main content

ACS4 - Consensus Standard

ACS4 customizes consensus mechanisms.

Interface

To customize, implement these five interfaces:

Methods

Method NameRequest TypeResponse TypeDescription
GetConsensusCommandgoogle.protobuf.BytesValueacs4.ConsensusCommandGenerate a consensus command based on contract state and the input public key.
GetConsensusExtraDatagoogle.protobuf.BytesValuegoogle.protobuf.BytesValueGenerate extra data when a block is generated.
GenerateConsensusTransactionsgoogle.protobuf.BytesValueacs4.TransactionListGenerate system transactions when a block is generated. Each block has one consensus transaction.
ValidateConsensusBeforeExecutiongoogle.protobuf.BytesValueacs4.ValidationResultVerify consensus info in the block header before execution.
ValidateConsensusAfterExecutiongoogle.protobuf.BytesValueacs4.ValidationResultVerify the state info written to consensus after execution.

Types

acs4.ConsensusCommand

FieldTypeDescription
limit_milliseconds_of_mining_blockint32Time limit for mining the next block.
hintbytesDiverse context according to the consensus protocol.
arranged_mining_timegoogle.protobuf.TimestampThe arranged mining time.
mining_due_timegoogle.protobuf.TimestampThe expiration time for mining.

acs4.TransactionList

FieldTypeDescription
transactionsaelf.TransactionConsensus system transactions.

acs4.ValidationResult

FieldTypeDescription
successboolIs successful.
messagestringError message.
is_re_triggerboolWhether to re-trigger mining.

aelf.Address

FieldTypeDescription
valuebytes

aelf.BinaryMerkleTree

FieldTypeDescription
nodesHashLeaf nodes.
rootHashRoot node hash.
leaf_countint32Leaf node count.

aelf.Hash

FieldTypeDescription
valuebytes

aelf.LogEvent

FieldTypeDescription
addressAddressContract address.
namestringName of the log event.
indexedbytesIndexed data for bloom.
non_indexedbytesNon-indexed data.

aelf.MerklePath

FieldTypeDescription
merkle_path_nodesMerklePathNodeMerkle path nodes.

aelf.MerklePathNode

FieldTypeDescription
hashHashNode hash.
is_left_child_nodeboolIs it a left child node?

aelf.SInt32Value

FieldTypeDescription
valuesint32

aelf.SInt64Value

FieldTypeDescription
valuesint64

aelf.ScopedStatePath

FieldTypeDescription
addressAddressScope address (contract address)
pathStatePathPath of contract state

aelf.SmartContractRegistration

FieldTypeDescription
categorysint32Contract code category (0: C#).
codebytesByte array of the contract code.
code_hashHashHash of the contract code.
is_system_contractboolIs it a system contract?
versionint32Current contract version.

aelf.StatePath

FieldTypeDescription
partsstringPartial state path.

aelf.Transaction

FieldTypeDescription
fromAddressSender's address.
toAddressContract address being called.
ref_block_numberint64Referenced block number.
ref_block_prefixbytesFirst four bytes of the referenced block hash.
method_namestringMethod name in the smart contract.
paramsbytesParameters for the smart contract method.
signaturebytesSignature including sender, target method, parameters, and block reference.

aelf.TransactionExecutingStateSet

FieldTypeDescription
writesTransactionExecutingStateSet.WritesEntryChanged states.
readsTransactionExecutingStateSet.ReadsEntryRead states.
deletesTransactionExecutingStateSet.DeletesEntryDeleted states.

aelf.TransactionExecutingStateSet.DeletesEntry

FieldTypeDescription
keystring
valuebool

aelf.TransactionExecutingStateSet.ReadsEntry

FieldTypeDescription
keystring
valuebool

aelf.TransactionExecutingStateSet.WritesEntry

FieldTypeDescription
keystring
valuebytes

aelf.TransactionResult

FieldTypeDescription
transaction_idHashTransaction ID.
statusTransactionResultStatusTransaction result status.
logsLogEventLog events.
bloombytesBloom filter for transaction logs.
return_valuebytesReturn value of the transaction execution.
block_numberint64Block height that packages the transaction.
block_hashHashBlock hash that packages the transaction.
errorstringFailed execution error message.

aelf.TransactionResultStatus

NameNumberDescription
NOT_EXISTED0Transaction result does not exist.
PENDING1Transaction is in the pool waiting to be packaged.
FAILED2Transaction execution failed.
MINED3Transaction executed successfully and packaged into a block.
CONFLICT4Conflicts with other transactions when executed in parallel.
PENDING_VALIDATION5Transaction is waiting for validation.
NODE_VALIDATION_FAILED6Transaction validation failed.

Usage

ACS4 methods correspond to the IConsensusService interface in the AElf.Kernel.Consensus project:

ACS4 MethodIConsensusService MethodMethodologyTiming
GetConsensusCommandTask TriggerConsensusAsyncWhen TriggerConsensusAsync is called, it will use the node's configured account to call the GetConsensusCommand method to obtain block information (ConsensusCommand)When the node starts; When the BestChainFoundEventData event is thrown; When consensus data validation fails and needs to be triggered again (IsReTrigger field is true).
GetConsensusExtraDataTask<byte[]> GetConsensusExtraDataAsyncWhen a node produces a block, it generates block header info via IBlockExtraDataService, which calls GetConsensusExtraData in the consensus contractWhen a node produces a new block.
GenerateConsensusTransactionsTask<List<Transaction>> GenerateConsensusTransactionsAsyncIn the process of generating new blocks, a consensus transaction needs to be generated as one of the system transactionsWhen a node produces a new block.
ValidateConsensusBeforeExecutionTask<bool> ValidateConsensusBeforeExecutionAsyncThe IBlockValidationProvider interface allows adding a new block validator. The consensus validator, ConsensusValidationProvider, calls ValidateConsensusBeforeExecutionWhen a node produces a new block.
ValidateConsensusAfterExecutionTask<bool> ValidateConsensusAfterExecutionAsyncThe implementation of ValidateBlockAfterExecuteAsync in ConsensusValidationProvider calls ValidateConsensusAfterExecution in the consensus contractWhen a node produces a new block.

Example

Refer to the AEDPoS contract implementation.