From dc8dcecb7b0b302c35531388bc1a9be4b16dbd20 Mon Sep 17 00:00:00 2001 From: ShangyanLi Date: Wed, 24 Apr 2019 22:42:33 -0400 Subject: [PATCH 1/4] [LOGOS-65] Correct hashing for token id (Issuance), add missing signature for issue additional; use higher precision clock --- logos/lib/epoch_time_util.hpp | 2 +- logos/node/rpc.cpp | 5 ----- logos/token/requests.cpp | 4 +++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/logos/lib/epoch_time_util.hpp b/logos/lib/epoch_time_util.hpp index 089cdb482..e58ca1413 100644 --- a/logos/lib/epoch_time_util.hpp +++ b/logos/lib/epoch_time_util.hpp @@ -14,7 +14,7 @@ using Seconds = std::chrono::seconds; using Minutes = std::chrono::minutes; using Hours = std::chrono::hours; -using Clock = boost::posix_time::second_clock; +using Clock = boost::posix_time::microsec_clock; using TimePoint = boost::posix_time::ptime; static const TimePoint Min_DT = TimePoint(boost::posix_time::min_date_time); diff --git a/logos/node/rpc.cpp b/logos/node/rpc.cpp index 954154405..ad0e72b40 100755 --- a/logos/node/rpc.cpp +++ b/logos/node/rpc.cpp @@ -1214,11 +1214,6 @@ void logos::rpc_handler::block_create () return; } - if(type == RequestType::Issuance) - { - auto issuance = static_pointer_cast(created_request); - issuance->token_id = GetTokenID(*issuance); - } std::shared_ptr info_ptr; if(!node.store.account_get(created_request->GetAccount(),info_ptr)) diff --git a/logos/token/requests.cpp b/logos/token/requests.cpp index c9246dbf8..1e6649a89 100644 --- a/logos/token/requests.cpp +++ b/logos/token/requests.cpp @@ -112,6 +112,8 @@ Issuance::Issuance(bool & error, } issuer_info = tree.get(ISSUER_INFO, ""); + + token_id = GetTokenID(symbol, name, origin, previous); SignAndHash(error, tree); } catch (...) @@ -479,7 +481,7 @@ IssueAdditional::IssueAdditional(bool & error, return; } - Hash(); + SignAndHash(error, tree); } catch(...) { From de3fba27697bbfebf8f0319a1fddf34e8b489b9c Mon Sep 17 00:00:00 2001 From: ShangyanLi Date: Thu, 25 Apr 2019 00:52:53 -0400 Subject: [PATCH 2/4] [LOGOS-65] temporary fix for incorrect population order of sequence & previous. need full fix later --- logos/node/rpc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/logos/node/rpc.cpp b/logos/node/rpc.cpp index ad0e72b40..49cab3950 100755 --- a/logos/node/rpc.cpp +++ b/logos/node/rpc.cpp @@ -1220,6 +1220,7 @@ void logos::rpc_handler::block_create () { created_request->sequence = info_ptr->block_count; created_request->previous = info_ptr->head; + created_request->Sign(prv.data, pub); } boost::property_tree::ptree response_l; From eec45cc7ffe0e82a4135a2c2be7be1e59d76df2c Mon Sep 17 00:00:00 2001 From: ShangyanLi Date: Thu, 25 Apr 2019 11:51:08 -0400 Subject: [PATCH 3/4] [LOGOS-65] switch to a more general clock type; add revoke offset for revoke source; --- logos/consensus/consensus_container.cpp | 2 +- logos/consensus/consensus_manager.cpp | 2 ++ logos/consensus/message_handler.cpp | 9 ++++----- logos/consensus/messages/receive_block.hpp | 2 -- .../persistence/request/request_persistence.cpp | 2 +- logos/consensus/request/request_backup_delegate.cpp | 6 +++--- logos/lib/epoch_time_util.hpp | 3 ++- logos/token/requests.hpp | 3 +++ logos/tx_acceptor/tx_acceptor_channel.hpp | 2 -- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/logos/consensus/consensus_container.cpp b/logos/consensus/consensus_container.cpp index 91fd1e4f9..0dd38bedc 100644 --- a/logos/consensus/consensus_container.cpp +++ b/logos/consensus/consensus_container.cpp @@ -271,7 +271,7 @@ ConsensusContainer::CancelTimer(ConsensusType CT) // 'manually' cancel the callback by setting _cancel_timer. // When the callback is invoked, it will check this value // and return early. - auto now = Clock::universal_time(); + auto now = Clock::now(); if(now < timer.expires_at() && !timer.cancel() && _timer_set[CT]) { LOG_DEBUG(_log) << "ConsensusContainer::CancelTimer " << ConsensusToName(CT) << " - force cancel."; diff --git a/logos/consensus/consensus_manager.cpp b/logos/consensus/consensus_manager.cpp index 45c007c48..6aebc8629 100644 --- a/logos/consensus/consensus_manager.cpp +++ b/logos/consensus/consensus_manager.cpp @@ -147,6 +147,8 @@ void ConsensusManager::OnMessageQueued() // Get most imminent timeout, if any, and schedule timer auto imminent_timeout = GetHandler().GetImminentTimeout(); if (imminent_timeout == Min_DT) return; + LOG_DEBUG(_log) << "ConsensusManager<" << ConsensusToName(CT) << ">::OnMessageQueued - " + << "imminent timeout is " << imminent_timeout << ", scheduling timer"; _scheduler.ScheduleTimer(CT, imminent_timeout); } } diff --git a/logos/consensus/message_handler.cpp b/logos/consensus/message_handler.cpp index 34915d6cc..a63d6aa73 100644 --- a/logos/consensus/message_handler.cpp +++ b/logos/consensus/message_handler.cpp @@ -8,7 +8,7 @@ MessageHandler::MessageHandler() template void MessageHandler::OnMessage(const MessagePtr & message, const Seconds & seconds) { - OnMessage(message, Clock::universal_time() + seconds); + OnMessage(message, Clock::now() + seconds); } template @@ -64,7 +64,7 @@ bool MessageHandler::PrimaryEmpty() std::lock_guard lock(_mutex); auto &expiration_index = _entries. template get<2>(); auto it = expiration_index.lower_bound(Min_DT); - auto end = expiration_index.upper_bound(Clock::universal_time()); + auto end = expiration_index.upper_bound(Clock::now()); return it == end; } @@ -73,7 +73,7 @@ auto MessageHandler::GetImminentTimeout() -> const TimePoint & { std::lock_guard lock(_mutex); auto &expiration_index = _entries. template get<2>(); - auto it = expiration_index.lower_bound(Clock::universal_time()); + auto it = expiration_index.lower_bound(Clock::now()); if (it == expiration_index.end()) return Min_DT; return it->expiration; } @@ -137,8 +137,7 @@ void RequestMessageHandler::MoveToTarget(RequestInternalQueue & queue, size_t si { std::lock_guard lock(_mutex); auto &expiration_index = _entries. template get<2>(); - - auto end = expiration_index.upper_bound(Clock::universal_time()); // strictly greater than + auto end = expiration_index.upper_bound(Clock::now()); // strictly greater than for(auto pos = expiration_index.lower_bound(Min_DT); pos != end && size != 0; size--) { diff --git a/logos/consensus/messages/receive_block.hpp b/logos/consensus/messages/receive_block.hpp index edf0f2284..82b84b041 100644 --- a/logos/consensus/messages/receive_block.hpp +++ b/logos/consensus/messages/receive_block.hpp @@ -62,5 +62,3 @@ struct ReceiveBlock BlockHash send_hash; uint16_t index2send = 0; }; - - diff --git a/logos/consensus/persistence/request/request_persistence.cpp b/logos/consensus/persistence/request/request_persistence.cpp index 24c1a1f7c..4ef028e32 100644 --- a/logos/consensus/persistence/request/request_persistence.cpp +++ b/logos/consensus/persistence/request/request_persistence.cpp @@ -995,7 +995,7 @@ void PersistenceManager::ApplyRequest(RequestPtr request, entry->balance -= revoke->transaction.amount; - ReceiveBlock receive(user_account.receive_head, revoke->GetHash(), 0); + ReceiveBlock receive(user_account.receive_head, revoke->GetHash(), Revoke::REVOKE_OFFSET); user_account.receive_head = receive.Hash(); PlaceReceive(receive, timestamp, transaction); diff --git a/logos/consensus/request/request_backup_delegate.cpp b/logos/consensus/request/request_backup_delegate.cpp index 991cb16a5..685d49a7b 100644 --- a/logos/consensus/request/request_backup_delegate.cpp +++ b/logos/consensus/request/request_backup_delegate.cpp @@ -139,7 +139,7 @@ RequestBackupDelegate::HandleReject(const PrePrepare & message) // If reason is contain invalid request, still need to queue up requests we agree on std::lock_guard lock(_mutex); // SYL Integration fix _pre_prepare_hashes.clear(); - auto timeout = Clock::universal_time() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE); + auto timeout = Clock::now() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE); for(uint16_t i = 0; i < message.requests.size(); ++i) { if (!_rejection_map[i]) @@ -169,7 +169,7 @@ RequestBackupDelegate::HandleReject(const PrePrepare & message) { _handler.OnMessage(std::static_pointer_cast(message.requests[i]), timeout); } - _scheduler.ScheduleTimer(R, Clock::universal_time() + timeout); + _scheduler.ScheduleTimer(R, Clock::now() + timeout); } break; } @@ -194,7 +194,7 @@ RequestBackupDelegate::HandlePrePrepare(const PrePrepare & message) std::lock_guard lock(_mutex); // SYL Integration fix _pre_prepare_hashes.clear(); - auto timeout = Clock::universal_time() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE); + auto timeout = Clock::now() + GetTimeout(TIMEOUT_MIN, TIMEOUT_RANGE); for(uint64_t i = 0; i < message.requests.size(); ++i) { _pre_prepare_hashes.insert(message.requests[i]->GetHash()); diff --git a/logos/lib/epoch_time_util.hpp b/logos/lib/epoch_time_util.hpp index e58ca1413..db5755f28 100644 --- a/logos/lib/epoch_time_util.hpp +++ b/logos/lib/epoch_time_util.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include using Milliseconds = std::chrono::milliseconds; @@ -14,7 +15,7 @@ using Seconds = std::chrono::seconds; using Minutes = std::chrono::minutes; using Hours = std::chrono::hours; -using Clock = boost::posix_time::microsec_clock; +using Clock = boost::asio::deadline_timer::traits_type; using TimePoint = boost::posix_time::ptime; static const TimePoint Min_DT = TimePoint(boost::posix_time::min_date_time); diff --git a/logos/token/requests.hpp b/logos/token/requests.hpp index c79e90071..598a1059e 100644 --- a/logos/token/requests.hpp +++ b/logos/token/requests.hpp @@ -182,6 +182,9 @@ struct Revoke : TokenRequest bool operator==(const Request & other) const override; + // offset of 128 to facilitate index lookup from revoke source's receive + static constexpr uint16_t REVOKE_OFFSET = 0x0080; + AccountAddress source; Transaction transaction; }; diff --git a/logos/tx_acceptor/tx_acceptor_channel.hpp b/logos/tx_acceptor/tx_acceptor_channel.hpp index 40c88abb6..db5737b3f 100644 --- a/logos/tx_acceptor/tx_acceptor_channel.hpp +++ b/logos/tx_acceptor/tx_acceptor_channel.hpp @@ -10,8 +10,6 @@ #include #include -#include - namespace logos { class node_config; } /// Implements forwarding to the Delegate From 5406ed2d91a4c2fd594dabd31b2f67b9308baea5 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 25 Apr 2019 11:53:48 -0400 Subject: [PATCH 4/4] [LOGOS-65] change client_callback to output empty array instead of str of empty array --- logos/consensus/messages/messages.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/logos/consensus/messages/messages.hpp b/logos/consensus/messages/messages.hpp index 41d025fe3..10a244f8e 100644 --- a/logos/consensus/messages/messages.hpp +++ b/logos/consensus/messages/messages.hpp @@ -11,7 +11,7 @@ #include #include #include - +#include static constexpr size_t MAX_MSG_SIZE = 1024*1024; // TODO: Update based on new request types @@ -206,7 +206,9 @@ struct PostCommittedBlock : public MessagePrequel