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

Make ethSyncStatus coherent #2648

Merged
merged 5 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/ain-cpp-imports/src/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ pub mod ffi {
fn getMinRelayTxFee() -> u64;
fn getEthPrivKey(key: String) -> [u8; 32];
fn getStateInputJSON() -> String;
fn getHighestBlock() -> i32;
fn getCurrentHeight() -> i32;
fn getEthSyncStatus() -> [i64; 2];
fn getAttributeValues(mnview_ptr: usize) -> Attributes;
fn CppLogPrintf(message: String);
fn getDST20Tokens(mnview_ptr: usize) -> Vec<DST20Token>;
Expand Down
10 changes: 3 additions & 7 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ mod ffi {
pub fn getStateInputJSON() -> String {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getHighestBlock() -> i32 {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getCurrentHeight() -> i32 {
pub fn getEthSyncStatus() -> [i64; 2] {
unimplemented!("{}", UNIMPL_MSG)
}
pub fn getAttributeValues(_mnview_ptr: usize) -> Attributes {
Expand Down Expand Up @@ -194,9 +191,8 @@ pub fn get_state_input_json() -> Option<String> {

/// Returns current DVM block height and highest DVM block header seen
pub fn get_sync_status() -> Result<(i32, i32), Box<dyn Error>> {
let current_block = ffi::getCurrentHeight();
let highest_block = ffi::getHighestBlock();
Ok((current_block, highest_block))
let [current_block, highest_block] = ffi::getEthSyncStatus();
Ok((current_block as i32, highest_block as i32))
}

pub fn get_attribute_defaults(mnview_ptr: Option<usize>) -> ffi::Attributes {
Expand Down
16 changes: 9 additions & 7 deletions src/ffi/ffiexports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <logging.h>
#include <net.h>
#include <util/system.h>
#include <array>
#include <cstdint>

// TODO: Later switch this to u8 so we skip the
// conversion and is more efficient.
Expand Down Expand Up @@ -255,19 +257,19 @@ rust::string getStateInputJSON() {
return gArgs.GetArg("-ethstartstate", "");
}

int getHighestBlock() {
return pindexBestHeader ? pindexBestHeader->nHeight
: (int)::ChainActive().Height(); // return current block count if no peers
}

// Returns Major, Minor, Revision in format: "X.Y.Z"
rust::string getClientVersion() {
return rust::String(FormatVersionAndSuffix());
}

int getCurrentHeight() {
std::array<int64_t, 2> getEthSyncStatus() {
LOCK(cs_main);
return ::ChainActive().Height() ? (int)::ChainActive().Height() : -1;

auto currentHeight = ::ChainActive().Height() ? (int)::ChainActive().Height() : -1;
auto highestBlock = pindexBestHeader ? pindexBestHeader->nHeight
: (int)::ChainActive().Height(); // return current block count if no peers

return std::array<int64_t, 2>{currentHeight, highestBlock};
}

Attributes getAttributeValues(std::size_t mnview_ptr) {
Expand Down
3 changes: 1 addition & 2 deletions src/ffi/ffiexports.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ uint64_t getNativeTxSize(rust::Vec<uint8_t> rawTransaction);
uint64_t getMinRelayTxFee();
std::array<uint8_t, 32> getEthPrivKey(rust::string key);
rust::string getStateInputJSON();
int getHighestBlock();
int getCurrentHeight();
std::array<int64_t, 2> getEthSyncStatus();
Attributes getAttributeValues(std::size_t mnview_ptr);
void CppLogPrintf(rust::string message);
rust::vec<DST20Token> getDST20Tokens(std::size_t mnview_ptr);
Expand Down