Expose tick_height to bpf programs
This commit is contained in:
@ -188,6 +188,14 @@ SOL_FN_PREFIX void _sol_panic(uint64_t line) {
|
||||
_sol_panic(__LINE__); \
|
||||
}
|
||||
|
||||
/**
|
||||
* Information about the state of the cluster immediately before the program
|
||||
* started executing the current instruction
|
||||
*/
|
||||
typedef struct {
|
||||
uint64_t tick_height; /** Current ledger tick */
|
||||
} SolClusterInfo;
|
||||
|
||||
/**
|
||||
* De-serializes the input parameters into usable types
|
||||
*
|
||||
@ -206,6 +214,7 @@ SOL_FN_PREFIX void _sol_panic(uint64_t line) {
|
||||
* number of filled accounts in `ka_len_out`.
|
||||
* @param data On return, a pointer to the instruction data
|
||||
* @param data_len On return, the length in bytes of the instruction data
|
||||
* @param cluster_info If not NULL, fill cluster_info
|
||||
* @return Boolean true if successful
|
||||
*/
|
||||
SOL_FN_PREFIX bool sol_deserialize(
|
||||
@ -214,7 +223,8 @@ SOL_FN_PREFIX bool sol_deserialize(
|
||||
uint64_t ka_len,
|
||||
uint64_t *ka_len_out,
|
||||
const uint8_t **data,
|
||||
uint64_t *data_len
|
||||
uint64_t *data_len,
|
||||
SolClusterInfo *cluster_info
|
||||
) {
|
||||
|
||||
|
||||
@ -255,7 +265,11 @@ SOL_FN_PREFIX bool sol_deserialize(
|
||||
*data_len = *(uint64_t *) input;
|
||||
input += sizeof(uint64_t);
|
||||
*data = input;
|
||||
input += sizeof(*data_len);
|
||||
|
||||
if (cluster_info != NULL) {
|
||||
cluster_info->tick_height = *(uint64_t *) input;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ extern bool entrypoint(const uint8_t *input) {
|
||||
const uint8_t *data;
|
||||
uint64_t data_len;
|
||||
|
||||
if (!sol_deserialize(input, ka, NUM_KA, NULL, &data, &data_len)) {
|
||||
if (!sol_deserialize(input, ka, NUM_KA, NULL, &data, &data_len, NULL)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -9,12 +9,13 @@ extern bool entrypoint(const uint8_t *input) {
|
||||
uint64_t ka_len;
|
||||
const uint8_t *data;
|
||||
uint64_t data_len;
|
||||
SolClusterInfo info;
|
||||
|
||||
sol_log("noop++");
|
||||
|
||||
if (!sol_deserialize(input, ka, SOL_ARRAY_SIZE(ka), &ka_len, &data, &data_len)) {
|
||||
sol_log(__FILE__);
|
||||
if (!sol_deserialize(input, ka, SOL_ARRAY_SIZE(ka), &ka_len, &data, &data_len, &info)) {
|
||||
return false;
|
||||
}
|
||||
sol_log_64(info.tick_height, 0, 0, 0, 0);
|
||||
|
||||
// Log the provided account keys and instruction input data. In the case of
|
||||
// the no-op program, no account keys or input data are expected but real
|
||||
|
@ -9,12 +9,14 @@ extern bool entrypoint(const uint8_t *input) {
|
||||
uint64_t ka_len;
|
||||
const uint8_t *data;
|
||||
uint64_t data_len;
|
||||
SolClusterInfo info;
|
||||
|
||||
sol_log(__FILE__);
|
||||
|
||||
if (!sol_deserialize(input, ka, SOL_ARRAY_SIZE(ka), &ka_len, &data, &data_len)) {
|
||||
if (!sol_deserialize(input, ka, SOL_ARRAY_SIZE(ka), &ka_len, &data, &data_len, &info)) {
|
||||
return false;
|
||||
}
|
||||
sol_log_64(info.tick_height, 0, 0, 0, 0);
|
||||
|
||||
// Log the provided account keys and instruction input data. In the case of
|
||||
// the no-op program, no account keys or input data are expected but real
|
||||
|
Reference in New Issue
Block a user