packages.valory.connections.abci.connection
Connection to interact with an ABCI server.
DEFAULT_
LISTEN_
ADDRESS
nosec
MAX_
READ_
IN_
BYTES
Max we'll consume on a read stream (1 MiB)
MAX_
VARINT_
BYTES
Max size of varint we support
DecodeVarintError Objects
class DecodeVarintError(Exception)
This exception is raised when an error occurs while decoding a varint.
EncodeVarintError Objects
class EncodeVarintError(Exception)
This exception is raised when an error occurs while encoding a varint.
TooLargeVarint Objects
class TooLargeVarint(Exception)
This exception is raised when a message with varint exceeding the max size is received.
__
init__
def __init__(received_size: int, max_size: int = MAX_READ_IN_BYTES)
Initialize the exception object.
Arguments:
received_size
: the received size.max_size
: the maximum amount the connection supports.
ShortBufferLengthError Objects
class ShortBufferLengthError(Exception)
This exception is raised when the buffer length is shorter than expected.
__
init__
def __init__(expected_length: int, data: bytes)
Initialize the exception object.
Arguments:
expected_length
: the expected length to be readdata
: the data actually read
_
TendermintABCISerializer Objects
class _TendermintABCISerializer()
(stateless) utility class to encode/decode messages for the communication with Tendermint.
encode_
varint
@classmethod
def encode_varint(cls, number: int) -> bytes
Encode a number in varint coding.
decode_
varint
@classmethod
async def decode_varint(cls,
buffer: asyncio.StreamReader,
max_length: int = MAX_VARINT_BYTES) -> int
Decode a number from its varint coding.
Arguments:
buffer
: the buffer to read from.max_length
: the max number of bytes that can be read.
Raises:
None
: DecodeVarintError if the varint could not be decoded.None
: EOFError if EOF byte is read and the process of decoding a varint has not started.
Returns:
the decoded int.
write_
message
@classmethod
def write_message(cls, message: Response) -> bytes
Write a message in a buffer.
VarintMessageReader Objects
class VarintMessageReader()
Varint message reader.
__
init__
def __init__(reader: asyncio.StreamReader) -> None
Initialize the reader.
read_
next_
message
async def read_next_message() -> bytes
Read next message.
read_
until
async def read_until(n: int) -> bytes
Wait until n bytes are read from the stream.
ABCIApplicationServicer Objects
class ABCIApplicationServicer(types_pb2_grpc.ABCIApplicationServicer)
Implements the gRPC servicer (handler)
__
init__
def __init__(request_queue: asyncio.Queue, dialogues: AbciDialogues,
target_skill: str)
Initializes the abci handler.
Arguments:
request_queue
: queue holding translated abci messages.dialogues
: dialoguestarget_skill
: target skill of messages
send
async def send(envelope: Envelope) -> Response
Returns response to the waiting request
:param: envelope: Envelope to be returned
Echo
async def Echo(request: RequestEcho,
context: grpc.ServicerContext) -> ResponseEcho
Handles "Echo" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
Flush
async def Flush(request: RequestFlush,
context: grpc.ServicerContext) -> ResponseFlush
Handles "Flush" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
Info
async def Info(request: RequestInfo,
context: grpc.ServicerContext) -> ResponseInfo
Handles "Info" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
SetOption
async def SetOption(request: RequestSetOption,
context: grpc.ServicerContext) -> ResponseSetOption
Handles "SetOption" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
DeliverTx
async def DeliverTx(request: RequestDeliverTx,
context: grpc.ServicerContext) -> ResponseDeliverTx
Handles "DeliverTx" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
CheckTx
async def CheckTx(request: RequestCheckTx,
context: grpc.ServicerContext) -> ResponseCheckTx
Handles "CheckTx" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
Query
async def Query(request: RequestQuery,
context: grpc.ServicerContext) -> ResponseQuery
Handles "Query" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
Commit
async def Commit(request: RequestCommit,
context: grpc.ServicerContext) -> ResponseCommit
Handles "Commit" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
InitChain
async def InitChain(request: RequestInitChain,
context: grpc.ServicerContext) -> ResponseInitChain
Handles "InitChain" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
BeginBlock
async def BeginBlock(request: RequestBeginBlock,
context: grpc.ServicerContext) -> ResponseBeginBlock
Handles "BeginBlock" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
EndBlock
async def EndBlock(request: RequestEndBlock,
context: grpc.ServicerContext) -> ResponseEndBlock
Handles "EndBlock" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
ListSnapshots
async def ListSnapshots(
request: RequestListSnapshots,
context: grpc.ServicerContext) -> ResponseListSnapshots
Handles "ListSnapshots" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
OfferSnapshot
async def OfferSnapshot(
request: RequestOfferSnapshot,
context: grpc.ServicerContext) -> ResponseOfferSnapshot
Handles "OfferSnapshot" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
LoadSnapshotChunk
async def LoadSnapshotChunk(
request: RequestLoadSnapshotChunk,
context: grpc.ServicerContext) -> ResponseLoadSnapshotChunk
Handles "LoadSnapshotChunk" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
ApplySnapshotChunk
async def ApplySnapshotChunk(
request: RequestApplySnapshotChunk,
context: grpc.ServicerContext) -> ResponseApplySnapshotChunk
Handles "ApplySnapshotChunk" gRPC requests
:param: request: The request from the Tendermint node :param: context: The request context :return: the Echo response
GrpcServerChannel Objects
class GrpcServerChannel()
gRPC server channel to handle incoming communication from the Tendermint node.
__
init__
def __init__(target_skill_id: PublicId,
address: str,
port: int,
logger: Optional[Logger] = None)
Initialize the gRPC server.
Arguments:
target_skill_id
: the public id of the target skill.address
: the listen address.port
: the port to listen from.logger
: the logger.
is_
stopped
@property
def is_stopped() -> bool
Check that the channel is stopped.
connect
async def connect(loop: AbstractEventLoop) -> None
Connect.
Arguments:
loop
: asyncio event loop
disconnect
async def disconnect() -> None
Disconnect the channel
get_
message
async def get_message() -> Envelope
Get a message from the queue.
send
async def send(envelope: Envelope) -> None
Send a message.
TcpServerChannel Objects
class TcpServerChannel()
TCP server channel to handle incoming communication from the Tendermint node.
__
init__
def __init__(target_skill_id: PublicId,
address: str,
port: int,
logger: Optional[Logger] = None)
Initialize the TCP server.
Arguments:
target_skill_id
: the public id of the target skill.address
: the listen address.port
: the port to listen from.logger
: the logger.
is_
stopped
@property
def is_stopped() -> bool
Check that the channel is stopped.
connect
async def connect(loop: AbstractEventLoop) -> None
Connect.
Upon TCP Channel connection, start the TCP Server asynchronously.
Arguments:
loop
: asyncio event loop
disconnect
async def disconnect() -> None
Disconnect the channel
receive_
messages
async def receive_messages(reader: asyncio.StreamReader,
writer: asyncio.StreamWriter) -> None
Receive incoming messages.
get_
message
async def get_message() -> Envelope
Get a message from the queue.
send
async def send(envelope: Envelope) -> None
Send a message.
StoppableThread Objects
class StoppableThread(Thread)
Thread class with a stop() method.
__
init__
def __init__(*args: Any, **kwargs: Any) -> None
Initialise the thread.
stop
def stop() -> None
Set the stop event.
stopped
def stopped() -> bool
Check if the thread is stopped.
TendermintParams Objects
class TendermintParams()
Tendermint node parameters.
__
init__
def __init__(proxy_app: str,
rpc_laddr: str = DEFAULT_RPC_LISTEN_ADDRESS,
p2p_laddr: str = DEFAULT_P2P_LISTEN_ADDRESS,
p2p_seeds: Optional[List[str]] = None,
consensus_create_empty_blocks: bool = True,
home: Optional[str] = None,
use_grpc: bool = False)
Initialize the parameters to the Tendermint node.
Arguments:
proxy_app
: ABCI address.rpc_laddr
: RPC address.p2p_laddr
: P2P address.p2p_seeds
: P2P seeds.consensus_create_empty_blocks
: if true, Tendermint node creates empty blocks.home
: Tendermint's home directory.use_grpc
: Whether to use a gRPC server, or TCP
__
str__
def __str__() -> str
Get the string representation.
build_
node_
command
def build_node_command(debug: bool = False) -> List[str]
Build the 'node' command.
get_
node_
command_
kwargs
@staticmethod
def get_node_command_kwargs() -> Dict
Get the node command kwargs
TendermintNode Objects
class TendermintNode()
A class to manage a Tendermint node.
__
init__
def __init__(params: TendermintParams,
logger: Optional[Logger] = None,
write_to_log: bool = False)
Initialize a Tendermint node.
Arguments:
params
: the parameters.logger
: the logger.write_to_log
: Write to log file.
init
def init() -> None
Initialize Tendermint node.
start
def start(debug: bool = False) -> None
Start a Tendermint node process.
stop
def stop() -> None
Stop a Tendermint node process.
log
def log(line: str) -> None
Open and write a line to the log file.
prune_
blocks
def prune_blocks() -> int
Prune blocks from the Tendermint state
reset_
genesis_
file
def reset_genesis_file(genesis_time: str, initial_height: str,
period_count: str) -> None
Reset genesis file.
ABCIServerConnection Objects
class ABCIServerConnection(Connection)
ABCI server.
__
init__
def __init__(**kwargs: Any) -> None
Initialize the connection.
Arguments:
kwargs
: keyword arguments passed to component base
connect
async def connect() -> None
Set up the connection.
In the implementation, remember to update 'connection_status' accordingly.
disconnect
async def disconnect() -> None
Tear down the connection.
In the implementation, remember to update 'connection_status' accordingly.
send
async def send(envelope: Envelope) -> None
Send an envelope.
Arguments:
envelope
: the envelope to send.
receive
async def receive(*args: Any, **kwargs: Any) -> Optional[Envelope]
Receive an envelope. Blocking.
Arguments:
args
: arguments to receivekwargs
: keyword arguments to receive
Returns:
the envelope received, if present. # noqa: DAR202