From 86ce351fc341785451b87dc01560838a15363176 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 5 Apr 2018 12:51:27 -0500 Subject: [PATCH 01/73] Improvements for blind vote publishing - Move code for broadcasting blind vote to p2p network and applying data to success handler of tx broadcast - Add popups when publishing blind vote --- src/main/proto/pb.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 406cb62..3c5b67f 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1418,7 +1418,7 @@ message MyVote { } message ParamChangeEvent { - // We use odingal instead of Enum as enaums in PB are a pain... as well we want to be more flexible at changes + // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes int32 dao_param_ordinal = 1; int64 value = 2; int32 block_height = 3; From 016d3b75034fa7f805807696a8f7d6191d5b733f Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 7 Apr 2018 21:22:47 -0500 Subject: [PATCH 02/73] Renaming - VoteResult to Vote - LongVoteResult to LongVote - BooleanVoteResult to BooleanVote --- src/main/proto/pb.proto | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 3c5b67f..d73a804 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1399,7 +1399,7 @@ message RemoveAltcoinProposalPayload { message Proposal { ProposalPayload proposal_payload = 1; - VoteResult vote_result = 2; + Vote vote = 2; map extra_data = 3; oneof message { CompensationRequest compensation_request = 4; @@ -1450,18 +1450,18 @@ message ChangeParamProposal { message RemoveAltcoinProposal { } -message VoteResult { +message Vote { oneof message { - BooleanVoteResult boolean_vote_result = 1; - LongVoteResult long_vote_result = 2; + BooleanVote boolean_vote = 1; + LongVote long_vote = 2; } } -message BooleanVoteResult { +message BooleanVote { bool accepted = 1; } -message LongVoteResult { +message LongVote { uint64 value = 1; } From daae653ae5209f27d569917e28ec16403d828eee Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 8 Apr 2018 12:07:14 -0500 Subject: [PATCH 03/73] Remove RevealedVote --- src/main/proto/pb.proto | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index d73a804..800b85a 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1432,12 +1432,6 @@ message BlindVote { map extra_data = 5; } -message RevealedVote { - ProposalList proposal_list = 1; - BlindVote blind_vote = 2; - string reveal_tx_id = 3; -} - message CompensationRequest { } From 747e9338c48f26b2655b85c9ac2df697571dced3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 11 Apr 2018 13:51:20 -0500 Subject: [PATCH 04/73] Refactor proposal domain and make it more thread safe - Add MyProposalService and ProposalListService to split up responsibility and threading boundaries - Make ProposalService running in parser thread. Refactor resonsibilities. - Add thread context aware listeners - Use injectable NodeExecutor to make parsre thread accessible for thread context aware listeners - Add stream() method and Iterable interface to PersistableList - Add ProposalFactory to create proposals from its payload - Add ProposalPayload and BlindVoteList to Tx - Add getLastOutput method to Tx --- .../common/ThreadContextAwareListener.java | 35 +++++++++++++++++++ src/main/java/bisq/common/UserThread.java | 3 ++ .../proto/persistable/PersistableList.java | 14 ++++++-- 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 src/main/java/bisq/common/ThreadContextAwareListener.java diff --git a/src/main/java/bisq/common/ThreadContextAwareListener.java b/src/main/java/bisq/common/ThreadContextAwareListener.java new file mode 100644 index 0000000..a7a9b2f --- /dev/null +++ b/src/main/java/bisq/common/ThreadContextAwareListener.java @@ -0,0 +1,35 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.common; + +import java.util.concurrent.Executor; + +/** + * Used for supporting to define the thread in which the listener is executed. + */ +public interface ThreadContextAwareListener { + // Default executor used for calling the handlers is user thread. + // Listener who want to get called in a custom thread need to overwrite that method. + default Executor getExecutor() { + return UserThread.getExecutor(); + } + + default void execute(Runnable runnable) { + getExecutor().execute(runnable); + } +} diff --git a/src/main/java/bisq/common/UserThread.java b/src/main/java/bisq/common/UserThread.java index 838b548..0ed9b2e 100644 --- a/src/main/java/bisq/common/UserThread.java +++ b/src/main/java/bisq/common/UserThread.java @@ -30,6 +30,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import lombok.Getter; + // Helps run delayed and periodic actions in the caller thread. public class UserThread { private static final Logger log = LoggerFactory.getLogger(UserThread.class); @@ -53,6 +55,7 @@ public static void setTimerClass(Class timerClass) { timerClass = FrameRateTimer.class; } + @Getter private static Executor executor; public static void execute(Runnable command) { diff --git a/src/main/java/bisq/common/proto/persistable/PersistableList.java b/src/main/java/bisq/common/proto/persistable/PersistableList.java index 1e8515d..9632a33 100644 --- a/src/main/java/bisq/common/proto/persistable/PersistableList.java +++ b/src/main/java/bisq/common/proto/persistable/PersistableList.java @@ -23,13 +23,14 @@ import java.util.HashSet; import java.util.List; import java.util.function.Function; +import java.util.stream.Stream; import lombok.Getter; import lombok.Setter; import lombok.experimental.Delegate; -public class PersistableList implements PersistableEnvelope { - @Delegate +public class PersistableList implements PersistableEnvelope, Iterable { + @Delegate(excludes = ExcludesDelegateMethods.class) @Getter @Setter private List list; @@ -58,8 +59,17 @@ public PersistableList(HashSet set, Function, Message> toProto) { this.toProto = toProto; } + // this.stream() does not compile for unknown reasons, so add that manual delegate method + public Stream stream() { + return list.stream(); + } + @Override public Message toProtoMessage() { return toProto.apply(list); } + + private interface ExcludesDelegateMethods { + Stream stream(); + } } From f0b13856b1b3066d203f159f17deab03199dc977 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 11 Apr 2018 20:47:17 -0500 Subject: [PATCH 05/73] Remove mutable fields of Tx, TxOutput and TxInput in PB definition --- src/main/proto/pb.proto | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index fe4b22b..3391901 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -423,7 +423,6 @@ message PubKeyScript { message TxInput { string connected_tx_output_tx_id = 1; int32 connected_tx_output_index = 2; - TxOutput connected_tx_output = 3; } message SpentInfo { @@ -460,10 +459,6 @@ message TxOutput { string address = 5; bytes op_return_data = 6; int32 block_height = 7; - bool is_unspent = 8; - bool is_verified = 9; - TxOutputType tx_output_type = 10; - SpentInfo spent_info = 11; } enum TxType { @@ -490,10 +485,6 @@ message Tx { int64 time = 5; repeated TxInput inputs = 6; repeated TxOutput outputs = 7; - int64 burnt_fee = 8; - TxType tx_type = 9; - bool is_ssuance_tx = 10; - int32 issuance_block_height = 11; } message BsqBlock { From d2d2d8a34c4c5ec79524548eaf8fc2d1b9658bb0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 11 Apr 2018 20:57:47 -0500 Subject: [PATCH 06/73] Refactorings (WIP) - Move TxIdIndexTuple as inner class to TxOutput and rename it to Key - Remove TxIdIndexTuple from PB (was never used) --- src/main/proto/pb.proto | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 3391901..d4e43b1 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -495,10 +495,6 @@ message BsqBlock { repeated Tx txs = 5; } -message TxIdIndexTuple { - string tx_id = 1; - int32 index = 2; -} /////////////////////////////////////////////////////////////////////////////////////////// // Storage payload From 39708928fb43e3facea08ba9c640f48c450769aa Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 13 Apr 2018 09:38:13 -0500 Subject: [PATCH 07/73] Improve comment. Use Lombok. --- src/main/java/bisq/common/UserThread.java | 33 ++++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/bisq/common/UserThread.java b/src/main/java/bisq/common/UserThread.java index 0ed9b2e..b4d52d6 100644 --- a/src/main/java/bisq/common/UserThread.java +++ b/src/main/java/bisq/common/UserThread.java @@ -27,23 +27,26 @@ import java.lang.reflect.InvocationTargetException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import lombok.Getter; - -// Helps run delayed and periodic actions in the caller thread. +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + + +/** + * Defines which thread is used as user thread. The user thread is the the main thread in the single threaded context. + * For JavaFX it is usually the Platform::RunLater executor, for a headless application it it any single threaded + * executor. + * Additionally sets a timer class so JavaFX and headless applications can set different timers (UITimer for JavaFX + * otherwise we use teh default FrameRateTimer). + *

+ * Provides also methods for delayed and periodic executions. + */ +@Slf4j public class UserThread { - private static final Logger log = LoggerFactory.getLogger(UserThread.class); private static Class timerClass; - - public static Executor getExecutor() { - return executor; - } - - public static void setExecutor(Executor executor) { - UserThread.executor = executor; - } + @Getter + @Setter + private static Executor executor; public static void setTimerClass(Class timerClass) { UserThread.timerClass = timerClass; @@ -55,8 +58,6 @@ public static void setTimerClass(Class timerClass) { timerClass = FrameRateTimer.class; } - @Getter - private static Executor executor; public static void execute(Runnable command) { UserThread.executor.execute(command); From b2c01716bb6ed82c541f881da6f84708ca4a03a5 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 13 Apr 2018 12:07:05 -0500 Subject: [PATCH 08/73] Refactor handling of blocks in state class. We create a immutable data unit Block which contains an immutable list of blockchain related blocks (TxBlock) and an immutable list of non-blockchain related events. Service classes which produces StateChangeEvents like ProposalService registers as stateChangeEventListProvider and returns a list of StateChangeEvents when a new TxBlock arrives. The stateService collect all those returned lists and put it to the newly created immutable Block. - Rename BsqBlock to TxBlock - Create Block class containing txBlock as delegate and stateChangeEvents - Add registerStateChangeEventListProvider method for clients processing a new TxBlock and producing stateChangeEvents - Rename StateService listeners to blockListeners - Pass Block instead of TxBlock at blockListeners.onBlockAdded - Rename StateService.Listener to StateService.BlockListener - Rename ParamChangeEvent to ChangeParamEvent - Make ChangeParamEvent extending StateChangeEvent - Make ChangeParam implementing ProtectedStoragePayload --- src/main/proto/pb.proto | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index d4e43b1..10df58c 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -347,6 +347,7 @@ message StoragePayload { CompensationRequestPayload compensation_request_payload = 8; // deprecated. Not used anymore. ProposalPayload proposal_payload = 9; BlindVote blind_vote = 10; + ChangeParamPayload change_param_vote = 11; } } @@ -979,7 +980,7 @@ message PersistableEnvelope { ProposalList proposal_list = 17; MyVoteList my_vote_list = 18; BlindVoteList blind_vote_list = 19; - ParamChangeEventList param_change_event_list = 20; + ChangeParamEventList change_param_event_list = 20; } } @@ -1059,9 +1060,9 @@ message BlindVoteList { repeated BlindVote blind_vote = 1; } -message ParamChangeEventList { - repeated ParamChangeEvent param_change_event = 1; -} +/*message ChangeParamEventList { + repeated ChangeParamEvent param_change_event = 1; +}*/ // deprecated not used anymore message CompensationRequestList { @@ -1409,13 +1410,19 @@ message MyVote { string reveal_tx_id = 5; } -message ParamChangeEvent { +message ChangeParamPayload { // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes int32 dao_param_ordinal = 1; int64 value = 2; - int32 block_height = 3; } +message ChangeParamEvent { + // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes + ChangeParamPayload change_param_payload = 1; + int32 height = 2; +} + + message BlindVote { bytes encrypted_proposal_list = 1; string tx_id = 2; From 1d2b60888d987251746792d90dc1032a14546d91 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 13 Apr 2018 12:28:05 -0500 Subject: [PATCH 09/73] Rename ChangeParamEvent to AddChangeParamEvent --- src/main/proto/pb.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 10df58c..bda22d1 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1416,7 +1416,7 @@ message ChangeParamPayload { int64 value = 2; } -message ChangeParamEvent { +message AddChangeParamEvent { // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes ChangeParamPayload change_param_payload = 1; int32 height = 2; From 2528bc4438e2e8d9104e1cfc3242c9cf0910570c Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 13 Apr 2018 12:28:59 -0500 Subject: [PATCH 10/73] Remove ChangeParamEventList (WIP) --- src/main/proto/pb.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index bda22d1..cef2bf1 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -980,7 +980,7 @@ message PersistableEnvelope { ProposalList proposal_list = 17; MyVoteList my_vote_list = 18; BlindVoteList blind_vote_list = 19; - ChangeParamEventList change_param_event_list = 20; + /*ChangeParamEventList change_param_event_list = 20;*/ } } From 788e227072c85d6cca7cc0658a2a5423c668729f Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 14 Apr 2018 11:57:45 -0500 Subject: [PATCH 11/73] Change threading behaviour of ThreadContextAwareListeners - If executeOnUserThread is set call listeners directly without using executor.execute() to avoid that we need to wait until running task is complete - Dont use nodExecutor at readPersisted as that is called at startup so no need to change thread here - Remove getExecutor and execute default methods from ThreadContextAwareListener - Add executeOnUserThread default method to ThreadContextAwareListener - Add notifyHashMapChangedListenersOnRemove and notifyHashMapChangedListenersOnAdded to P2PDataStorage --- .../bisq/common/ThreadContextAwareListener.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/bisq/common/ThreadContextAwareListener.java b/src/main/java/bisq/common/ThreadContextAwareListener.java index a7a9b2f..21ccfdd 100644 --- a/src/main/java/bisq/common/ThreadContextAwareListener.java +++ b/src/main/java/bisq/common/ThreadContextAwareListener.java @@ -17,19 +17,14 @@ package bisq.common; -import java.util.concurrent.Executor; - /** * Used for supporting to define the thread in which the listener is executed. */ public interface ThreadContextAwareListener { - // Default executor used for calling the handlers is user thread. - // Listener who want to get called in a custom thread need to overwrite that method. - default Executor getExecutor() { - return UserThread.getExecutor(); - } - - default void execute(Runnable runnable) { - getExecutor().execute(runnable); + // If overwritten and false is returned the caller will map to the userThread, otherwise it will be called directly + // from the running thread. We do not user executor.execute() as we don't want to wait until the running task is + // completed. + default boolean executeOnUserThread() { + return true; } } From ebe53eba8889661bd99919d303c999caf31222cf Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 16 Apr 2018 22:38:27 -0500 Subject: [PATCH 12/73] Refactor state - Break up state and stateService - Add UserThreadStateService for access from user thread - Map state changes to UserThreadStateService - Add execute method to ThreadAwareListener --- ...ontextAwareListener.java => ThreadAwareListener.java} | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) rename src/main/java/bisq/common/{ThreadContextAwareListener.java => ThreadAwareListener.java} (84%) diff --git a/src/main/java/bisq/common/ThreadContextAwareListener.java b/src/main/java/bisq/common/ThreadAwareListener.java similarity index 84% rename from src/main/java/bisq/common/ThreadContextAwareListener.java rename to src/main/java/bisq/common/ThreadAwareListener.java index 21ccfdd..a618175 100644 --- a/src/main/java/bisq/common/ThreadContextAwareListener.java +++ b/src/main/java/bisq/common/ThreadAwareListener.java @@ -20,11 +20,18 @@ /** * Used for supporting to define the thread in which the listener is executed. */ -public interface ThreadContextAwareListener { +public interface ThreadAwareListener { // If overwritten and false is returned the caller will map to the userThread, otherwise it will be called directly // from the running thread. We do not user executor.execute() as we don't want to wait until the running task is // completed. default boolean executeOnUserThread() { return true; } + + default void execute(Runnable runnable) { + if (executeOnUserThread()) + UserThread.execute(runnable); + else + runnable.run(); + } } From f1083510ddba826597435f98fc9dd09418a66810 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 16 Apr 2018 23:07:30 -0500 Subject: [PATCH 13/73] Add comments --- src/main/java/bisq/common/ThreadAwareListener.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/bisq/common/ThreadAwareListener.java b/src/main/java/bisq/common/ThreadAwareListener.java index a618175..14f8faa 100644 --- a/src/main/java/bisq/common/ThreadAwareListener.java +++ b/src/main/java/bisq/common/ThreadAwareListener.java @@ -22,8 +22,7 @@ */ public interface ThreadAwareListener { // If overwritten and false is returned the caller will map to the userThread, otherwise it will be called directly - // from the running thread. We do not user executor.execute() as we don't want to wait until the running task is - // completed. + // from the running thread. default boolean executeOnUserThread() { return true; } From c302c3f8b69ee7472d1f5a09aa0a951243eb71d0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 18 Apr 2018 22:26:55 -0500 Subject: [PATCH 14/73] Rename Proposal to Ballot and ProposalPayload to Proposal --- src/main/proto/pb.proto | 74 +++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 43 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index cef2bf1..5595e79 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -344,10 +344,9 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; - CompensationRequestPayload compensation_request_payload = 8; // deprecated. Not used anymore. - ProposalPayload proposal_payload = 9; - BlindVote blind_vote = 10; - ChangeParamPayload change_param_vote = 11; + Proposal proposal = 8; + BlindVote blind_vote = 9; + ChangeParamPayload change_param_vote = 10; } } @@ -971,16 +970,12 @@ message PersistableEnvelope { UserPayload user_payload = 10; PaymentAccountList payment_account_list = 11; - CompensationRequestPayload compensation_request_payload = 12; // deprecated. Not used anymore. - VoteItemsList vote_items_list = 13; // deprecated. Not used anymore. - BsqBlockChain bsq_block_chain = 14; + BsqBlockChain bsq_block_chain = 12; - PersistableNetworkPayloadList persistable_network_payload_list = 15; - CompensationRequestList compensation_request_list = 16; // deprecated. Not used anymore. - ProposalList proposal_list = 17; - MyVoteList my_vote_list = 18; - BlindVoteList blind_vote_list = 19; - /*ChangeParamEventList change_param_event_list = 20;*/ + PersistableNetworkPayloadList persistable_network_payload_list = 13; + BallotList ballot_list = 14; + MyVoteList my_vote_list = 15; + BlindVoteList blind_vote_list = 16; } } @@ -1048,8 +1043,8 @@ message PaymentAccountList { repeated PaymentAccount payment_account = 1; } -message ProposalList { - repeated Proposal proposal = 1; +message BallotList { + repeated Ballot ballot = 1; } message MyVoteList { @@ -1064,9 +1059,6 @@ message BlindVoteList { repeated ChangeParamEvent param_change_event = 1; }*/ -// deprecated not used anymore -message CompensationRequestList { -} /////////////////////////////////////////////////////////////////////////////////////////// // Offer/Trade @@ -1352,11 +1344,7 @@ message BsqBlockChain { Tx genesis_tx = 7; } -// deprecated. Not used anymore. -message VoteItemsList { -} - -message ProposalPayload { +message Proposal { uint32 version = 1; int64 creation_date = 2; string uid = 3; @@ -1368,42 +1356,42 @@ message ProposalPayload { string tx_id = 9; map extra_data = 10; oneof message { - CompensationRequestPayload compensation_request_payload = 11; - GenericProposalPayload generic_proposal_payload = 12; - ChangeParamProposalPayload change_param_proposal_payload = 13; - RemoveAltcoinProposalPayload remove_altcoin_proposal_payload = 14; + CompensationRequestProposal compensation_request_proposal = 11; + GenericProposal generic_proposal = 12; + ChangeParamProposal change_param_proposal = 13; + RemoveAltcoinProposal remove_altcoin_proposal = 14; } } -message CompensationRequestPayload { +message CompensationRequestProposal { int64 requested_bsq = 1; string bsq_address = 2; } -message GenericProposalPayload { +message GenericProposal { } -message ChangeParamProposalPayload { +message ChangeParamProposal { } -message RemoveAltcoinProposalPayload { +message RemoveAltcoinProposal { string currency_code = 1; } -message Proposal { - ProposalPayload proposal_payload = 1; +message Ballot { + Proposal proposal = 1; Vote vote = 2; map extra_data = 3; oneof message { - CompensationRequest compensation_request = 4; - GenericProposal generic_proposal = 5; - ChangeParamProposal change_param_proposal = 6; - RemoveAltcoinProposal remove_altcoin_proposal = 7; + CompensationRequestBallot compensation_request_ballot = 4; + GenericBallot generic_ballot = 5; + ChangeParamBallot change_param_ballot = 6; + RemoveAltcoinBallot remove_altcoin_ballot = 7; } } message MyVote { - ProposalList proposal_list = 1; + BallotList ballot_list = 1; bytes secret_key_encoded = 2; BlindVote blind_vote = 3; int64 date = 4; @@ -1424,23 +1412,23 @@ message AddChangeParamEvent { message BlindVote { - bytes encrypted_proposal_list = 1; + bytes encrypted_ballot_list = 1; string tx_id = 2; int64 stake = 3; bytes owner_pub_key_as_encoded = 4; map extra_data = 5; } -message CompensationRequest { +message CompensationRequestBallot { } -message GenericProposal { +message GenericBallot { } -message ChangeParamProposal { +message ChangeParamBallot { } -message RemoveAltcoinProposal { +message RemoveAltcoinBallot { } message Vote { From ac581922704f0f8235d2dd435efd4852d0b24c6b Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 19 Apr 2018 18:55:37 -0500 Subject: [PATCH 15/73] Split BlindVote in BlindVote and BlindVotePayload --- src/main/proto/pb.proto | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 5595e79..aa70e97 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -345,7 +345,7 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; Proposal proposal = 8; - BlindVote blind_vote = 9; + BlindVotePayload blind_vote_payload = 9; ChangeParamPayload change_param_vote = 10; } } @@ -1410,13 +1410,16 @@ message AddChangeParamEvent { int32 height = 2; } - message BlindVote { bytes encrypted_ballot_list = 1; string tx_id = 2; int64 stake = 3; - bytes owner_pub_key_as_encoded = 4; - map extra_data = 5; +} + +message BlindVotePayload { + BlindVote blind_vote = 1; + bytes owner_pub_key_as_encoded = 2; + map extra_data = 3; } message CompensationRequestBallot { From 97b4c732ce88e7bd9a56bf4da44ec9009850be38 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 19 Apr 2018 19:01:45 -0500 Subject: [PATCH 16/73] Rename classed with term CompensationRequest to Compensation --- src/main/proto/pb.proto | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index aa70e97..376d5d4 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1356,14 +1356,14 @@ message Proposal { string tx_id = 9; map extra_data = 10; oneof message { - CompensationRequestProposal compensation_request_proposal = 11; + CompensationProposal compensation_proposal = 11; GenericProposal generic_proposal = 12; ChangeParamProposal change_param_proposal = 13; RemoveAltcoinProposal remove_altcoin_proposal = 14; } } -message CompensationRequestProposal { +message CompensationProposal { int64 requested_bsq = 1; string bsq_address = 2; } @@ -1383,7 +1383,7 @@ message Ballot { Vote vote = 2; map extra_data = 3; oneof message { - CompensationRequestBallot compensation_request_ballot = 4; + CompensationBallot compensation_ballot = 4; GenericBallot generic_ballot = 5; ChangeParamBallot change_param_ballot = 6; RemoveAltcoinBallot remove_altcoin_ballot = 7; @@ -1422,7 +1422,7 @@ message BlindVotePayload { map extra_data = 3; } -message CompensationRequestBallot { +message CompensationBallot { } message GenericBallot { From 2ebe51e35e2cad30012c3835a1ceb3a204a69313 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 19 Apr 2018 20:11:25 -0500 Subject: [PATCH 17/73] Split Proposal into Proposal and ProposalPayload --- src/main/proto/pb.proto | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 376d5d4..0d800fa 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -344,7 +344,7 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; - Proposal proposal = 8; + ProposalPayload proposal_payload = 8; BlindVotePayload blind_vote_payload = 9; ChangeParamPayload change_param_vote = 10; } @@ -1352,14 +1352,12 @@ message Proposal { string title = 5; string description = 6; string link = 7; - bytes owner_pub_key_encoded = 8; - string tx_id = 9; - map extra_data = 10; + string tx_id = 8; oneof message { - CompensationProposal compensation_proposal = 11; - GenericProposal generic_proposal = 12; - ChangeParamProposal change_param_proposal = 13; - RemoveAltcoinProposal remove_altcoin_proposal = 14; + CompensationProposal compensation_proposal = 9; + GenericProposal generic_proposal = 10; + ChangeParamProposal change_param_proposal = 11; + RemoveAltcoinProposal remove_altcoin_proposal = 12; } } @@ -1378,6 +1376,12 @@ message RemoveAltcoinProposal { string currency_code = 1; } +message ProposalPayload { + Proposal proposal = 1; + bytes owner_pub_key_encoded = 8; + map extra_data = 10; +} + message Ballot { Proposal proposal = 1; Vote vote = 2; From 9a3e001957b667cf3a1fdf67e6b46f449bd62012 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 19 Apr 2018 20:51:03 -0500 Subject: [PATCH 18/73] Add option key daoActivated to enable all dao features for dev --- src/main/java/bisq/common/app/DevEnv.java | 33 ++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/bisq/common/app/DevEnv.java b/src/main/java/bisq/common/app/DevEnv.java index 8a949cb..e972be1 100644 --- a/src/main/java/bisq/common/app/DevEnv.java +++ b/src/main/java/bisq/common/app/DevEnv.java @@ -17,20 +17,10 @@ package bisq.common.app; -import bisq.common.CommonOptionKeys; - -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.name.Names; - import lombok.extern.slf4j.Slf4j; @Slf4j public class DevEnv { - public static void setup(Injector injector) { - DevEnv.setDevMode(injector.getInstance(Key.get(Boolean.class, Names.named(CommonOptionKeys.USE_DEV_MODE)))); - } - // Was used for P2P network stress test to adjust several setting for the tests (e.g. use lower btc fees for offers,..) public static final boolean STRESS_TEST_MODE = false; @@ -55,12 +45,31 @@ public static void setDevMode(boolean devMode) { DevEnv.devMode = devMode; } - public static final boolean DAO_PHASE2_ACTIVATED = false; - public static final boolean DAO_TRADING_ACTIVATED = false; + private static final boolean DAO_PHASE2_ACTIVATED = false; + private static final boolean DAO_TRADING_ACTIVATED = false; + + private static boolean daoActivated = false; + + public static boolean isDaoActivated() { + return daoActivated; + } + + public static void setDaoActivated(boolean daoActivated) { + DevEnv.daoActivated = daoActivated; + } + public static void logErrorAndThrowIfDevMode(String msg) { log.error(msg); if (devMode) throw new RuntimeException(msg); } + + public static boolean isDaoPhase2Activated() { + return DAO_PHASE2_ACTIVATED || daoActivated; + } + + public static boolean isDaoTradingActivated() { + return DAO_TRADING_ACTIVATED || daoActivated; + } } From 735ce9cd566136512007e8c36bb1a512fe34f998 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 20 Apr 2018 09:55:26 -0500 Subject: [PATCH 19/73] Rename state change event classes --- src/main/proto/pb.proto | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 0d800fa..ade0543 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -346,7 +346,7 @@ message StoragePayload { OfferPayload offer_payload = 7; ProposalPayload proposal_payload = 8; BlindVotePayload blind_vote_payload = 9; - ChangeParamPayload change_param_vote = 10; + ParamChange param_change = 10; } } @@ -1402,15 +1402,14 @@ message MyVote { string reveal_tx_id = 5; } -message ChangeParamPayload { +message ParamChange { // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes - int32 dao_param_ordinal = 1; + int32 param_ordinal = 1; int64 value = 2; } -message AddChangeParamEvent { - // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes - ChangeParamPayload change_param_payload = 1; +message ParamChangeEvent { + ParamChange param_change = 1; int32 height = 2; } From 7bb288604f8cec92a0748b7a9720e6ac4d828f15 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 20 Apr 2018 10:39:37 -0500 Subject: [PATCH 20/73] Move bisq.core.dao.consensus.vote.myvote package to bisq.core.dao --- src/main/proto/pb.proto | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index ade0543..203c4a9 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1385,12 +1385,11 @@ message ProposalPayload { message Ballot { Proposal proposal = 1; Vote vote = 2; - map extra_data = 3; oneof message { - CompensationBallot compensation_ballot = 4; - GenericBallot generic_ballot = 5; - ChangeParamBallot change_param_ballot = 6; - RemoveAltcoinBallot remove_altcoin_ballot = 7; + CompensationBallot compensation_ballot = 3; + GenericBallot generic_ballot = 4; + ChangeParamBallot change_param_ballot = 5; + RemoveAltcoinBallot remove_altcoin_ballot = 6; } } From df652922802275c13667f2de01d48d6170e911fe Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 21 Apr 2018 20:52:33 -0500 Subject: [PATCH 21/73] Remove usage of PeriodServiceFacade and ThreadAwareListener --- .../java/bisq/common/ThreadAwareListener.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/bisq/common/ThreadAwareListener.java diff --git a/src/main/java/bisq/common/ThreadAwareListener.java b/src/main/java/bisq/common/ThreadAwareListener.java deleted file mode 100644 index 14f8faa..0000000 --- a/src/main/java/bisq/common/ThreadAwareListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.common; - -/** - * Used for supporting to define the thread in which the listener is executed. - */ -public interface ThreadAwareListener { - // If overwritten and false is returned the caller will map to the userThread, otherwise it will be called directly - // from the running thread. - default boolean executeOnUserThread() { - return true; - } - - default void execute(Runnable runnable) { - if (executeOnUserThread()) - UserThread.execute(runnable); - else - runnable.run(); - } -} From 5822e6d864d7c83146ce6b09061649def7339cec Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 22 Apr 2018 00:09:47 -0500 Subject: [PATCH 22/73] Cleanup --- src/main/proto/pb.proto | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 203c4a9..79e9780 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1394,11 +1394,12 @@ message Ballot { } message MyVote { - BallotList ballot_list = 1; - bytes secret_key_encoded = 2; - BlindVote blind_vote = 3; - int64 date = 4; - string reveal_tx_id = 5; + int32 height = 1; + BallotList ballot_list = 2; + bytes secret_key_encoded = 3; + BlindVote blind_vote = 4; + int64 date = 5; + string reveal_tx_id = 6; } message ParamChange { From 7e41b5a5f5a7a7202b4820cf7fbdd63792ed004e Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 23 Apr 2018 19:26:58 -0500 Subject: [PATCH 23/73] Cleanup protobuffer file --- src/main/proto/pb.proto | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 79e9780..70d908f 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1043,22 +1043,6 @@ message PaymentAccountList { repeated PaymentAccount payment_account = 1; } -message BallotList { - repeated Ballot ballot = 1; -} - -message MyVoteList { - repeated MyVote my_vote = 1; -} - -message BlindVoteList { - repeated BlindVote blind_vote = 1; -} - -/*message ChangeParamEventList { - repeated ChangeParamEvent param_change_event = 1; -}*/ - /////////////////////////////////////////////////////////////////////////////////////////// // Offer/Trade @@ -1345,13 +1329,13 @@ message BsqBlockChain { } message Proposal { - uint32 version = 1; - int64 creation_date = 2; - string uid = 3; - string name = 4; - string title = 5; - string description = 6; - string link = 7; + string uid = 1; + string name = 2; + string title = 3; + string description = 4; + string link = 5; + uint32 version = 6; + int64 creation_date = 7; string tx_id = 8; oneof message { CompensationProposal compensation_proposal = 9; @@ -1378,8 +1362,8 @@ message RemoveAltcoinProposal { message ProposalPayload { Proposal proposal = 1; - bytes owner_pub_key_encoded = 8; - map extra_data = 10; + bytes owner_pub_key_encoded = 2; + map extra_data = 3; } message Ballot { @@ -1393,13 +1377,20 @@ message Ballot { } } -message MyVote { - int32 height = 1; - BallotList ballot_list = 2; - bytes secret_key_encoded = 3; - BlindVote blind_vote = 4; - int64 date = 5; - string reveal_tx_id = 6; +message CompensationBallot { +} + +message GenericBallot { +} + +message ChangeParamBallot { +} + +message RemoveAltcoinBallot { +} + +message BallotList { + repeated Ballot ballot = 1; } message ParamChange { @@ -1413,6 +1404,23 @@ message ParamChangeEvent { int32 height = 2; } +message ParamChangeEventList { + repeated ParamChangeEvent param_change_event = 1; +} + +message MyVote { + int32 height = 1; + BallotList ballot_list = 2; + bytes secret_key_encoded = 3; + BlindVote blind_vote = 4; + int64 date = 5; + string reveal_tx_id = 6; +} + +message MyVoteList { + repeated MyVote my_vote = 1; +} + message BlindVote { bytes encrypted_ballot_list = 1; string tx_id = 2; @@ -1425,16 +1433,8 @@ message BlindVotePayload { map extra_data = 3; } -message CompensationBallot { -} - -message GenericBallot { -} - -message ChangeParamBallot { -} - -message RemoveAltcoinBallot { +message BlindVoteList { + repeated BlindVote blind_vote = 1; } message Vote { From 37b12defa2ae569ee6cde76aebeece00b37a89da Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 23 Apr 2018 21:30:57 -0500 Subject: [PATCH 24/73] Add PB definition for State, Block and TxBlock - Rename classed, methods and fields with *BsqBlock* to *TxBlock* --- src/main/proto/pb.proto | 237 +++++++++++++++++++++------------------- 1 file changed, 123 insertions(+), 114 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 70d908f..a4c33fe 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -50,9 +50,9 @@ message NetworkEnvelope { PrivateNotificationMessage private_notification_message = 27; - GetBsqBlocksRequest get_bsq_blocks_request = 28; - GetBsqBlocksResponse get_bsq_blocks_response = 29; - NewBsqBlockBroadcastMessage new_bsq_block_broadcast_message = 30; + GetTxBlocksRequest get_tx_blocks_request = 28; + GetTxBlocksResponse get_tx_blocks_response = 29; + NewTxBlockBroadcastMessage new_tx_block_broadcast_message = 30; AddPersistableNetworkPayloadMessage add_persistable_network_payload_message = 31; } @@ -286,18 +286,18 @@ message PrivateNotificationMessage { // DAO -message GetBsqBlocksRequest { +message GetTxBlocksRequest { int32 from_block_height = 1; int32 nonce = 2; } -message GetBsqBlocksResponse { - repeated BsqBlock bsq_blocks = 1; +message GetTxBlocksResponse { + repeated TxBlock tx_blocks = 1; int32 request_nonce = 2; } -message NewBsqBlockBroadcastMessage { - BsqBlock bsq_block = 1; +message NewTxBlockBroadcastMessage { + TxBlock tx_block = 1; } /////////////////////////////////////////////////////////////////////////////////////////// @@ -398,103 +398,6 @@ message PaymentAccountFilter { string value = 3; } -// DAO - -enum ScriptType { - PB_ERROR_SCRIPT_TYPES = 0; - PUB_KEY = 1; - PUB_KEY_HASH = 2; - SCRIPT_HASH = 3; - MULTISIG = 4; - NULL_DATA = 5; - WITNESS_V0_KEYHASH = 6; - WITNESS_V0_SCRIPTHASH = 7; - NONSTANDARD = 8; -} - -message PubKeyScript { - int32 req_sigs = 1; - ScriptType script_type = 2; - repeated string addresses = 3; - string asm = 4; - string hex = 5; -} - -message TxInput { - string connected_tx_output_tx_id = 1; - int32 connected_tx_output_index = 2; -} - -message SpentInfo { - int64 block_height = 1; - string tx_id = 2; - int32 input_index = 3; -} - -enum TxOutputType { - PB_ERROR_TX_OUTPUT_TYPE = 0; - UNDEFINED = 1; - GENESIS_OUTPUT = 2; - BSQ_OUTPUT = 3; - BTC_OUTPUT = 4; - PROPOSAL_OP_RETURN_OUTPUT = 5; - COMP_REQ_OP_RETURN_OUTPUT = 6; - ISSUANCE_CANDIDATE_OUTPUT = 7; - BLIND_VOTE_LOCK_STAKE_OUTPUT = 8; - BLIND_VOTE_OP_RETURN_OUTPUT = 9; - VOTE_REVEAL_UNLOCK_STAKE_OUTPUT = 10; - VOTE_REVEAL_OP_RETURN_OUTPUT = 11; - BOND_LOCK = 12; - BOND_LOCK_OP_RETURN_OUTPUT = 13; - BOND_UNLOCK = 14; - BOND_UNLOCK_OP_RETURN_OUTPUT = 15; - INVALID_OUTPUT = 16; -} - -message TxOutput { - int32 index = 1; - int64 value = 2; - string tx_id = 3; - PubKeyScript pub_key_script = 4; - string address = 5; - bytes op_return_data = 6; - int32 block_height = 7; -} - -enum TxType { - PB_ERROR_TX_TYPE = 0; - UNDEFINED_TX_TYPE = 1; - UNVERIFIED = 2; - INVALID = 3; - GENESIS = 4; - TRANSFER_BSQ = 5; - PAY_TRADE_FEE = 6; - PROPOSAL = 7; - COMPENSATION_REQUEST = 8; - BLIND_VOTE = 9; - VOTE_REVEAL = 10; - LOCK_UP = 11; - UN_LOCK = 12; -} - -message Tx { - string tx_version = 1; - string id = 2; - int32 block_height = 3; - string block_hash = 4; - int64 time = 5; - repeated TxInput inputs = 6; - repeated TxOutput outputs = 7; -} - -message BsqBlock { - int32 height = 1; - int64 time = 2; - string hash = 3; - string previous_block_hash = 4; - repeated Tx txs = 5; -} - /////////////////////////////////////////////////////////////////////////////////////////// // Storage payload @@ -970,7 +873,7 @@ message PersistableEnvelope { UserPayload user_payload = 10; PaymentAccountList payment_account_list = 11; - BsqBlockChain bsq_block_chain = 12; + State state = 12; PersistableNetworkPayloadList persistable_network_payload_list = 13; BallotList ballot_list = 14; @@ -1314,18 +1217,124 @@ message UserPayload { Mediator registered_mediator = 11; } + /////////////////////////////////////////////////////////////////////////////////////////// // DAO /////////////////////////////////////////////////////////////////////////////////////////// -message BsqBlockChain { - repeated BsqBlock bsq_blocks = 1; - map tx_map = 2; - map unspent_tx_outputs_map = 3; - string genesis_tx_id = 4; - int32 genesis_block_height = 5; - int32 chain_head_height = 6; - Tx genesis_tx = 7; +// blockchain + +message TxBlock { + int32 height = 1; + int64 time = 2; + string hash = 3; + string previous_block_hash = 4; + repeated Tx txs = 5; +} + +message Tx { + string tx_version = 1; + string id = 2; + int32 block_height = 3; + string block_hash = 4; + int64 time = 5; + repeated TxInput inputs = 6; + repeated TxOutput outputs = 7; +} + +enum TxType { + PB_ERROR_TX_TYPE = 0; + UNDEFINED_TX_TYPE = 1; + UNVERIFIED = 2; + INVALID = 3; + GENESIS = 4; + TRANSFER_BSQ = 5; + PAY_TRADE_FEE = 6; + PROPOSAL = 7; + COMPENSATION_REQUEST = 8; + BLIND_VOTE = 9; + VOTE_REVEAL = 10; + LOCK_UP = 11; + UN_LOCK = 12; +} + +message TxInput { + string connected_tx_output_tx_id = 1; + int32 connected_tx_output_index = 2; +} + +message TxOutput { + int32 index = 1; + int64 value = 2; + string tx_id = 3; + PubKeyScript pub_key_script = 4; + string address = 5; + bytes op_return_data = 6; + int32 block_height = 7; +} + +enum TxOutputType { + PB_ERROR_TX_OUTPUT_TYPE = 0; + UNDEFINED = 1; + GENESIS_OUTPUT = 2; + BSQ_OUTPUT = 3; + BTC_OUTPUT = 4; + PROPOSAL_OP_RETURN_OUTPUT = 5; + COMP_REQ_OP_RETURN_OUTPUT = 6; + ISSUANCE_CANDIDATE_OUTPUT = 7; + BLIND_VOTE_LOCK_STAKE_OUTPUT = 8; + BLIND_VOTE_OP_RETURN_OUTPUT = 9; + VOTE_REVEAL_UNLOCK_STAKE_OUTPUT = 10; + VOTE_REVEAL_OP_RETURN_OUTPUT = 11; + BOND_LOCK = 12; + BOND_LOCK_OP_RETURN_OUTPUT = 13; + BOND_UNLOCK = 14; + BOND_UNLOCK_OP_RETURN_OUTPUT = 15; + INVALID_OUTPUT = 16; +} + +message SpentInfo { + int64 block_height = 1; + string tx_id = 2; + int32 input_index = 3; +} + +enum ScriptType { + PB_ERROR_SCRIPT_TYPES = 0; + PUB_KEY = 1; + PUB_KEY_HASH = 2; + SCRIPT_HASH = 3; + MULTISIG = 4; + NULL_DATA = 5; + WITNESS_V0_KEYHASH = 6; + WITNESS_V0_SCRIPTHASH = 7; + NONSTANDARD = 8; +} + +message PubKeyScript { + int32 req_sigs = 1; + ScriptType script_type = 2; + repeated string addresses = 3; + string asm = 4; + string hex = 5; +} + +// other dao data + +message Block { + TxBlock tx_block = 1; + // TODO not sure yet if we store other data in block, if not we can omit Block and use TxBlock directly +} +message State { + string genesis_tx_id = 1; + int32 genesis_block_height = 2; + repeated Block blocks = 3; + map tx_type_map = 4; + map burnt_fee_map = 5; + map issuance_block_height_map = 6; + map unspent_tx_output_map = 7; + map tx_output_type_map = 8; + map spent_info_map = 9; } message Proposal { From d7a7621d2f658bca3d2dad2e8e68d62763b210df Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 24 Apr 2018 09:54:53 -0500 Subject: [PATCH 25/73] Add Cycle, PhaseWrapper and chainHeight and cycles in State to PB definitions --- src/main/proto/pb.proto | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index a4c33fe..91778ce 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -398,7 +398,6 @@ message PaymentAccountFilter { string value = 3; } - /////////////////////////////////////////////////////////////////////////////////////////// // Storage payload /////////////////////////////////////////////////////////////////////////////////////////// @@ -946,7 +945,6 @@ message PaymentAccountList { repeated PaymentAccount payment_account = 1; } - /////////////////////////////////////////////////////////////////////////////////////////// // Offer/Trade /////////////////////////////////////////////////////////////////////////////////////////// @@ -1217,7 +1215,6 @@ message UserPayload { Mediator registered_mediator = 11; } - /////////////////////////////////////////////////////////////////////////////////////////// // DAO /////////////////////////////////////////////////////////////////////////////////////////// @@ -1319,7 +1316,18 @@ message PubKeyScript { string hex = 5; } -// other dao data +// dao data + + +message PhaseWrapper { + string phase_name = 1; + int32 duration = 2; +} + +message Cycle { + repeated PhaseWrapper phase_wrapper_list = 1; + int32 height_of_first_lock = 2; +} message Block { TxBlock tx_block = 1; @@ -1328,13 +1336,15 @@ message Block { message State { string genesis_tx_id = 1; int32 genesis_block_height = 2; - repeated Block blocks = 3; - map tx_type_map = 4; - map burnt_fee_map = 5; - map issuance_block_height_map = 6; - map unspent_tx_output_map = 7; - map tx_output_type_map = 8; - map spent_info_map = 9; + int32 chain_height = 3; + repeated Block blocks = 4; + map tx_type_map = 5; + map burnt_fee_map = 6; + map issuance_block_height_map = 7; + map unspent_tx_output_map = 8; + map tx_output_type_map = 9; + map spent_info_map = 10; + repeated Cycle cycles = 11; } message Proposal { From 2b9ed0b54f8c8bed5807ea936c5ec91cdc8ef9c0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 24 Apr 2018 11:00:27 -0500 Subject: [PATCH 26/73] Remove Meta data from block. - Remove Block - Rename TxBlock to Block - Rename classes, methods with *TxBlock* to *Block* - Remove stateChangeEventsProviders --- src/main/proto/pb.proto | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 91778ce..b23fab9 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -50,9 +50,9 @@ message NetworkEnvelope { PrivateNotificationMessage private_notification_message = 27; - GetTxBlocksRequest get_tx_blocks_request = 28; - GetTxBlocksResponse get_tx_blocks_response = 29; - NewTxBlockBroadcastMessage new_tx_block_broadcast_message = 30; + GetBlocksRequest get_blocks_request = 28; + GetBlocksResponse get_blocks_response = 29; + NewBlockBroadcastMessage new_block_broadcast_message = 30; AddPersistableNetworkPayloadMessage add_persistable_network_payload_message = 31; } @@ -286,18 +286,18 @@ message PrivateNotificationMessage { // DAO -message GetTxBlocksRequest { +message GetBlocksRequest { int32 from_block_height = 1; int32 nonce = 2; } -message GetTxBlocksResponse { - repeated TxBlock tx_blocks = 1; +message GetBlocksResponse { + repeated Block blocks = 1; int32 request_nonce = 2; } -message NewTxBlockBroadcastMessage { - TxBlock tx_block = 1; +message NewBlockBroadcastMessage { + Block block = 1; } /////////////////////////////////////////////////////////////////////////////////////////// @@ -1221,7 +1221,7 @@ message UserPayload { // blockchain -message TxBlock { +message Block { int32 height = 1; int64 time = 2; string hash = 3; @@ -1329,10 +1329,6 @@ message Cycle { int32 height_of_first_lock = 2; } -message Block { - TxBlock tx_block = 1; - // TODO not sure yet if we store other data in block, if not we can omit Block and use TxBlock directly -} message State { string genesis_tx_id = 1; int32 genesis_block_height = 2; From 3483807b03ec2f5c9732d4a4529eff71488e2e16 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 24 Apr 2018 16:35:18 -0500 Subject: [PATCH 27/73] Refactor ParamChange domain --- src/main/proto/pb.proto | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index b23fab9..9ef4786 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -346,7 +346,6 @@ message StoragePayload { OfferPayload offer_payload = 7; ProposalPayload proposal_payload = 8; BlindVotePayload blind_vote_payload = 9; - ParamChange param_change = 10; } } @@ -1316,17 +1315,17 @@ message PubKeyScript { string hex = 5; } -// dao data +// dao data -message PhaseWrapper { - string phase_name = 1; +message DaoPhase { + int32 phase_ordinal = 1; int32 duration = 2; } message Cycle { - repeated PhaseWrapper phase_wrapper_list = 1; - int32 height_of_first_lock = 2; + int32 height_of_first_lock = 1; + repeated DaoPhase dao_phase = 2; } message State { @@ -1341,6 +1340,7 @@ message State { map tx_output_type_map = 9; map spent_info_map = 10; repeated Cycle cycles = 11; + map param_change_by_block_height = 12; } message Proposal { @@ -1408,19 +1408,8 @@ message BallotList { repeated Ballot ballot = 1; } -message ParamChange { - // We use ordinal instead of Enum as enums in PB are a pain... as well we want to be more flexible at changes - int32 param_ordinal = 1; - int64 value = 2; -} - -message ParamChangeEvent { - ParamChange param_change = 1; - int32 height = 2; -} - -message ParamChangeEventList { - repeated ParamChangeEvent param_change_event = 1; +message ParamChangeMap { + map map = 1; } message MyVote { From 5fd868387952d8a2d5e75724dc59d3d0e5f676d6 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 25 Apr 2018 12:42:26 -0500 Subject: [PATCH 28/73] Store only proposal TxId + vote instead of whole ballot in BlindVote - Add BallotFactory - Change encryptedBallotList to encryptedVotes --- src/main/proto/pb.proto | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 9ef4786..d217a8c 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1425,8 +1425,17 @@ message MyVoteList { repeated MyVote my_vote = 1; } +message VoteWithProposalTxId { + string proposal_tx_id = 1; + Vote vote = 2; +} + +message VoteWithProposalTxIdList { + repeated VoteWithProposalTxId item = 1; +} + message BlindVote { - bytes encrypted_ballot_list = 1; + bytes encrypted_votes = 1; string tx_id = 2; int64 stake = 3; } From 086ed89fbb3c45a95c172b177442a4383469c8d1 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 25 Apr 2018 13:08:20 -0500 Subject: [PATCH 29/73] Use single threaded executor for rpc service - We want to avoid out or order results of blocks. Would require a queue sorted by block hash to support multiple rpc threads. Also the calls for chain height, hash and txs need to be executed in correct order. Leave that for later optimization if needed --- src/main/java/bisq/common/util/Utilities.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/bisq/common/util/Utilities.java b/src/main/java/bisq/common/util/Utilities.java index 393fbd2..5f7fa75 100644 --- a/src/main/java/bisq/common/util/Utilities.java +++ b/src/main/java/bisq/common/util/Utilities.java @@ -71,7 +71,6 @@ import java.util.Set; import java.util.TimeZone; import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; @@ -111,12 +110,12 @@ public static ListeningExecutorService getListeningSingleThreadExecutor(String n return MoreExecutors.listeningDecorator(getSingleThreadExecutor(name)); } - public static ExecutorService getSingleThreadExecutor(String name) { + public static ListeningExecutorService getSingleThreadExecutor(String name) { final ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat(name) .setDaemon(true) .build(); - return Executors.newSingleThreadExecutor(threadFactory); + return MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor(threadFactory)); } public static ListeningExecutorService getListeningExecutorService(String name, From 5645ddb0fb619e81a3e9edbf90fb6094aeb64f7c Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 27 Apr 2018 11:38:04 -0500 Subject: [PATCH 30/73] Add AccountAgeWitnessMap --- src/main/proto/pb.proto | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 66d3c5d..0df5b3b 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -993,6 +993,8 @@ message PersistableEnvelope { MyVoteList my_vote_list = 18; BlindVoteList blind_vote_list = 19; ParamChangeEventList param_change_event_list = 20; + AccountAgeWitnessMap account_age_witness_map = 21; + TradeStatistics2Map trade_statistics2_map = 22; } } @@ -1026,6 +1028,14 @@ message PersistableNetworkPayloadList { repeated PersistableNetworkPayload items = 1; } +message AccountAgeWitnessMap { + map items = 1; +} + +message TradeStatistics2Map { + map items = 1; +} + message PeerList { repeated Peer peer = 1; } @@ -1275,9 +1285,6 @@ message TradingPeer { int64 current_date = 14; } -message AccountAgeWitnessMap { - map account_age_witness_map = 1; -} /////////////////////////////////////////////////////////////////////////////////////////// // Dispute From 9d498d70e67097492c7797c957fb19415a5e77fe Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 27 Apr 2018 14:08:18 -0500 Subject: [PATCH 31/73] Use a list in PB for AccountAgeWitnessStore for reducing disk space (no map with hash) - Transfer data from PersistableNetworkPayloadMapService to new data stores - Make getHashAsByteArray publis static - Rename AccountAgeWitnessMap to AccountAgeWitnessStore and and TradeStatistics2Map to TradeStatistics2Store --- src/main/proto/pb.proto | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 0df5b3b..de807cd 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -987,14 +987,14 @@ message PersistableEnvelope { VoteItemsList vote_items_list = 13; // deprecated. Not used anymore. BsqBlockChain bsq_block_chain = 14; - PersistableNetworkPayloadList persistable_network_payload_list = 15; + PersistableNetworkPayloadList persistable_network_payload_list = 15; // deprecated. Not used anymore. CompensationRequestList compensation_request_list = 16; // deprecated. Not used anymore. ProposalList proposal_list = 17; MyVoteList my_vote_list = 18; BlindVoteList blind_vote_list = 19; ParamChangeEventList param_change_event_list = 20; - AccountAgeWitnessMap account_age_witness_map = 21; - TradeStatistics2Map trade_statistics2_map = 22; + AccountAgeWitnessStore account_age_witness_store = 21; + TradeStatistics2Store trade_statistics2_store = 22; } } @@ -1024,16 +1024,19 @@ message PersistedEntryMap { map persisted_entry_map = 1; } +// deprecated. Not used anymore. message PersistableNetworkPayloadList { repeated PersistableNetworkPayload items = 1; } -message AccountAgeWitnessMap { - map items = 1; +// We use a list not a hash map to save disc space. The hash can be calculated from the payload anyway +message AccountAgeWitnessStore { + repeated AccountAgeWitness items = 1; } -message TradeStatistics2Map { - map items = 1; +// We use a list not a hash map to save disc space. The hash can be calculated from the payload anyway +message TradeStatistics2Store { + repeated TradeStatistics2 items = 1; } message PeerList { From 9afe8e57609840d430c74c21da5fbda2abe7bc37 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 27 Apr 2018 19:27:35 -0500 Subject: [PATCH 32/73] Add append-only storage for Proposal and BlindVote (WIP) --- src/main/proto/pb.proto | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index afaafb3..7b73596 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -344,8 +344,8 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; - ProposalPayload proposal_payload = 8; - BlindVotePayload blind_vote_payload = 9; + ProposalProtectedStoragePayload proposal_protected_storage_payload = 8; + BlindVoteProtectedStoragePayload blind_vote_protected_storage_payload = 9; } } @@ -353,6 +353,8 @@ message PersistableNetworkPayload { oneof message { AccountAgeWitness account_age_witness = 1; TradeStatistics2 trade_statistics2 = 2; + ProposalPayload proposal_payload = 3; + BlindVotePayload blind_vote_payload = 4; } } @@ -877,9 +879,12 @@ message PersistableEnvelope { State state = 15; - BallotList ballot_list = 16; - MyVoteList my_vote_list = 17; - BlindVoteList blind_vote_list = 18; + ProposalStore proposal_store = 16; + BlindVoteStore blind_vote_store = 17; + BallotList ballot_list = 18; + MyVoteList my_vote_list = 19; + BlindVoteList blind_vote_list = 20; + } } @@ -1386,12 +1391,21 @@ message RemoveAltcoinProposal { string currency_code = 1; } -message ProposalPayload { +message ProposalProtectedStoragePayload { Proposal proposal = 1; bytes owner_pub_key_encoded = 2; map extra_data = 3; } +message ProposalPayload { + Proposal proposal = 1; + bytes hash = 2; +} + +message ProposalStore { + repeated ProposalPayload items = 1; +} + message Ballot { Proposal proposal = 1; Vote vote = 2; @@ -1451,7 +1465,7 @@ message BlindVote { int64 stake = 3; } -message BlindVotePayload { +message BlindVoteProtectedStoragePayload { BlindVote blind_vote = 1; bytes owner_pub_key_as_encoded = 2; map extra_data = 3; @@ -1461,6 +1475,15 @@ message BlindVoteList { repeated BlindVote blind_vote = 1; } +message BlindVoteStore { + repeated BlindVotePayload items = 1; +} + +message BlindVotePayload { + BlindVote blind_vote = 1; + bytes hash = 2; +} + message Vote { oneof message { BooleanVote boolean_vote = 1; From af9f16393d347aa00be97ed821529a8a6d3ccf61 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 27 Apr 2018 21:59:54 -0500 Subject: [PATCH 33/73] Update to merged changes from p2p network. Renaming --- src/main/proto/pb.proto | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 7b73596..9493e9e 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -353,8 +353,8 @@ message PersistableNetworkPayload { oneof message { AccountAgeWitness account_age_witness = 1; TradeStatistics2 trade_statistics2 = 2; - ProposalPayload proposal_payload = 3; - BlindVotePayload blind_vote_payload = 4; + ProposalAppendOnlyPayload proposal_append_only_payload = 3; + BlindVoteAppendOnlyPayload blind_vote_append_only_payload = 4; } } @@ -860,7 +860,7 @@ message USPostalMoneyOrderAccountPayload { message PersistableEnvelope { oneof message { SequenceNumberMap sequence_number_map = 1; - PersistedEntryMap persisted_entry_map = 2; + PersistedEntryMap persisted_entry_map = 2; // deprecated. Not used anymore. PeerList peer_list = 3; AddressEntryList address_entry_list = 4; NavigationPath navigation_path = 5; @@ -879,8 +879,8 @@ message PersistableEnvelope { State state = 15; - ProposalStore proposal_store = 16; - BlindVoteStore blind_vote_store = 17; + ProposalAppendOnlyStore proposal_append_only_store = 16; + BlindVoteAppendOnlyStore blind_vote_append_only_store = 17; BallotList ballot_list = 18; MyVoteList my_vote_list = 19; BlindVoteList blind_vote_list = 20; @@ -910,6 +910,7 @@ message MapValue { int64 time_stamp = 2; } +// deprecated. Not used anymore. message PersistedEntryMap { map persisted_entry_map = 1; } @@ -1397,13 +1398,13 @@ message ProposalProtectedStoragePayload { map extra_data = 3; } -message ProposalPayload { +message ProposalAppendOnlyPayload { Proposal proposal = 1; bytes hash = 2; } -message ProposalStore { - repeated ProposalPayload items = 1; +message ProposalAppendOnlyStore { + repeated ProposalAppendOnlyPayload items = 1; } message Ballot { @@ -1475,11 +1476,11 @@ message BlindVoteList { repeated BlindVote blind_vote = 1; } -message BlindVoteStore { - repeated BlindVotePayload items = 1; +message BlindVoteAppendOnlyStore { + repeated BlindVoteAppendOnlyPayload items = 1; } -message BlindVotePayload { +message BlindVoteAppendOnlyPayload { BlindVote blind_vote = 1; bytes hash = 2; } From b308411e53a1e9c9281756548d73c71fca6ffac4 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 27 Apr 2018 22:52:03 -0500 Subject: [PATCH 34/73] Add protected data storage for proposal and blind vote --- src/main/proto/pb.proto | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 9493e9e..ed77ba0 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -344,8 +344,8 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; - ProposalProtectedStoragePayload proposal_protected_storage_payload = 8; - BlindVoteProtectedStoragePayload blind_vote_protected_storage_payload = 9; + ProposalPayload proposal_payload = 8; + BlindVotePayload blind_vote_payload = 9; } } @@ -880,10 +880,12 @@ message PersistableEnvelope { State state = 15; ProposalAppendOnlyStore proposal_append_only_store = 16; - BlindVoteAppendOnlyStore blind_vote_append_only_store = 17; - BallotList ballot_list = 18; - MyVoteList my_vote_list = 19; - BlindVoteList blind_vote_list = 20; + ProposalStore proposal_store = 17; + BlindVoteAppendOnlyStore blind_vote_append_only_store = 18; + BlindVoteStore blind_vote_store = 19; + BallotList ballot_list = 20; + MyVoteList my_vote_list = 21; + BlindVoteList blind_vote_list = 22; } } @@ -1392,7 +1394,7 @@ message RemoveAltcoinProposal { string currency_code = 1; } -message ProposalProtectedStoragePayload { +message ProposalPayload { Proposal proposal = 1; bytes owner_pub_key_encoded = 2; map extra_data = 3; @@ -1407,6 +1409,10 @@ message ProposalAppendOnlyStore { repeated ProposalAppendOnlyPayload items = 1; } +message ProposalStore { + repeated ProtectedStorageEntry items = 1; +} + message Ballot { Proposal proposal = 1; Vote vote = 2; @@ -1466,7 +1472,7 @@ message BlindVote { int64 stake = 3; } -message BlindVoteProtectedStoragePayload { +message BlindVotePayload { BlindVote blind_vote = 1; bytes owner_pub_key_as_encoded = 2; map extra_data = 3; @@ -1480,6 +1486,10 @@ message BlindVoteAppendOnlyStore { repeated BlindVoteAppendOnlyPayload items = 1; } +message BlindVoteStore { + repeated ProtectedStorageEntry items = 1; +} + message BlindVoteAppendOnlyPayload { BlindVote blind_vote = 1; bytes hash = 2; From 72e016d56d019f36f74b322b9c7636e942977cb3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 30 Apr 2018 12:28:22 -0500 Subject: [PATCH 35/73] Let proposal domain handle all its relevant use cases - Previously we wrapped by default a proposal into a ballot and used that in the UI. We changed that so in the proposal phase there is only the proposal used. Once we enter the blind vote phase we move to ballot representation. - We also changed that the proposals for the append-only data store gets filled by the proposal domain once entering the blind vote phase. - We moved also the publishing, removal and republishing to the myProposalListService. --- src/main/proto/pb.proto | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index ed77ba0..42f3308 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -883,9 +883,10 @@ message PersistableEnvelope { ProposalStore proposal_store = 17; BlindVoteAppendOnlyStore blind_vote_append_only_store = 18; BlindVoteStore blind_vote_store = 19; - BallotList ballot_list = 20; - MyVoteList my_vote_list = 21; - BlindVoteList blind_vote_list = 22; + ProposalList proposal_list = 20; + BallotList ballot_list = 21; + MyVoteList my_vote_list = 22; + BlindVoteList blind_vote_list = 23; } } @@ -1436,6 +1437,10 @@ message ChangeParamBallot { message RemoveAltcoinBallot { } +message ProposalList { + repeated Proposal proposal = 1; +} + message BallotList { repeated Ballot ballot = 1; } From 77adb37db22cb4b84f37553cd6b0824aa4213255 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 1 May 2018 21:14:19 -0500 Subject: [PATCH 36/73] Remove unneeded Ballot subclasses --- src/main/proto/pb.proto | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 42f3308..393303a 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1417,24 +1417,6 @@ message ProposalStore { message Ballot { Proposal proposal = 1; Vote vote = 2; - oneof message { - CompensationBallot compensation_ballot = 3; - GenericBallot generic_ballot = 4; - ChangeParamBallot change_param_ballot = 5; - RemoveAltcoinBallot remove_altcoin_ballot = 6; - } -} - -message CompensationBallot { -} - -message GenericBallot { -} - -message ChangeParamBallot { -} - -message RemoveAltcoinBallot { } message ProposalList { From 39f6d2d98f761507cce47c5551759153659d191d Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 1 May 2018 23:03:34 -0500 Subject: [PATCH 37/73] Refactor handling of lists in BlindVote --- src/main/proto/pb.proto | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 393303a..76d8144 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -883,10 +883,10 @@ message PersistableEnvelope { ProposalStore proposal_store = 17; BlindVoteAppendOnlyStore blind_vote_append_only_store = 18; BlindVoteStore blind_vote_store = 19; - ProposalList proposal_list = 20; + MyProposalList my_proposal_list = 20; BallotList ballot_list = 21; MyVoteList my_vote_list = 22; - BlindVoteList blind_vote_list = 23; + MyBlindVoteList my_blind_vote_list = 23; } } @@ -1419,7 +1419,7 @@ message Ballot { Vote vote = 2; } -message ProposalList { +message MyProposalList { repeated Proposal proposal = 1; } @@ -1465,7 +1465,7 @@ message BlindVotePayload { map extra_data = 3; } -message BlindVoteList { +message MyBlindVoteList { repeated BlindVote blind_vote = 1; } From 24129f66e9c68603f9669da47e919db2d6c26869 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 5 May 2018 20:08:28 -0500 Subject: [PATCH 38/73] Use BlockHash and data for append-only store We add the blockHash of the 10th block in the break before the relevant phase as part of the hash in the appen-only data. Together with the date tolerance we get control over the time when the data has been added. This protects agains various attacks (data withhold and publish late attack). - Implement DateTolerantPayload at BlindVoteAppendOnlyPayload and ProposalAppendOnlyPayload - Implement ExpirablePayload at ProposalPayload and BlindVotePayload - Add blockHash and data at BlindVoteAppendOnlyPayload and ProposalAppendOnlyPayload - Add ClosedBallotsView --- src/main/java/bisq/common/crypto/Hash.java | 14 +++++++++++++- src/main/proto/pb.proto | 8 ++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/bisq/common/crypto/Hash.java b/src/main/java/bisq/common/crypto/Hash.java index 3b0dd86..820d8a1 100644 --- a/src/main/java/bisq/common/crypto/Hash.java +++ b/src/main/java/bisq/common/crypto/Hash.java @@ -21,6 +21,8 @@ import com.google.common.base.Charsets; +import org.spongycastle.crypto.digests.RIPEMD160Digest; + import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; @@ -65,11 +67,21 @@ public static byte[] getSha256Hash(Integer data) { } /** - * Calculates RIPEMD160(SHA256(input)). + * Calculates RIPEMD160(SHA256(data)). */ public static byte[] getSha256Ripemd160hash(byte[] data) { return Utils.sha256hash160(data); } + /** + * Calculates RIPEMD160(data). + */ + public static byte[] getRipemd160hash(byte[] data) { + RIPEMD160Digest digest = new RIPEMD160Digest(); + digest.update(data, 0, data.length); + byte[] out = new byte[20]; + digest.doFinal(out, 0); + return out; + } } diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 76d8144..ce5a88d 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1403,7 +1403,9 @@ message ProposalPayload { message ProposalAppendOnlyPayload { Proposal proposal = 1; - bytes hash = 2; + int64 date = 2; + bytes block_hash = 3; + bytes hash = 4; } message ProposalAppendOnlyStore { @@ -1479,7 +1481,9 @@ message BlindVoteStore { message BlindVoteAppendOnlyPayload { BlindVote blind_vote = 1; - bytes hash = 2; + int64 date = 2; + bytes block_hash = 3; + bytes hash = 4; } message Vote { From 25bccfe0eac86a46601cd5448067361a99c08c7d Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 8 Jun 2018 13:25:23 +0200 Subject: [PATCH 39/73] Remove protectedDataStore at blindVote - Fix issue with same address for change and issuance candidate (use freshReceiveAddress instead of currentReceiveAddress) - Check if issuance candidate ended up in an issuance tx at StateService.isBsqTxOutputType - Change dust value to 546 - Remove blockHash in BlindVoteAppendOnlyPayload --- src/main/proto/pb.proto | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 7e7472d..859489a 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -345,7 +345,6 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; ProposalPayload proposal_payload = 8; - BlindVotePayload blind_vote_payload = 9; } } @@ -890,11 +889,10 @@ message PersistableEnvelope { ProposalAppendOnlyStore proposal_append_only_store = 16; ProposalStore proposal_store = 17; BlindVoteAppendOnlyStore blind_vote_append_only_store = 18; - BlindVoteStore blind_vote_store = 19; - MyProposalList my_proposal_list = 20; - BallotList ballot_list = 21; - MyVoteList my_vote_list = 22; - MyBlindVoteList my_blind_vote_list = 23; + MyProposalList my_proposal_list = 19; + BallotList ballot_list = 20; + MyVoteList my_vote_list = 21; + MyBlindVoteList my_blind_vote_list = 22; } } @@ -1469,12 +1467,6 @@ message BlindVote { int64 stake = 3; } -message BlindVotePayload { - BlindVote blind_vote = 1; - bytes owner_pub_key_as_encoded = 2; - map extra_data = 3; -} - message MyBlindVoteList { repeated BlindVote blind_vote = 1; } @@ -1483,15 +1475,10 @@ message BlindVoteAppendOnlyStore { repeated BlindVoteAppendOnlyPayload items = 1; } -message BlindVoteStore { - repeated ProtectedStorageEntry items = 1; -} - message BlindVoteAppendOnlyPayload { BlindVote blind_vote = 1; int64 date = 2; - bytes block_hash = 3; - bytes hash = 4; + bytes hash = 3; } message Vote { From c86bc0c28c2cd1f1d4ff3a19197f5e65cc47657e Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 8 Jun 2018 14:17:29 +0200 Subject: [PATCH 40/73] Renaming payloads and stores Use temp prefix for protected data types and no prefix for append only data types - Rename ProposalPayload to TempProposalPayload - Rename ProposalStore to TempProposalStore - Rename ProposalAppendOnlyPayload to ProposalPayload - Rename ProposalAppendOnlyStore to ProposalStore - Rename BlindVoteAppendOnlyPayload to BlindVotePayload - Rename BlindVoteAppendOnlyStore to BlindVoteStore --- src/main/proto/pb.proto | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 859489a..4165be6 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -344,7 +344,7 @@ message StoragePayload { MailboxStoragePayload mailbox_storage_payload = 6; OfferPayload offer_payload = 7; - ProposalPayload proposal_payload = 8; + TempProposalPayload temp_proposal_payload = 8; } } @@ -352,8 +352,8 @@ message PersistableNetworkPayload { oneof message { AccountAgeWitness account_age_witness = 1; TradeStatistics2 trade_statistics2 = 2; - ProposalAppendOnlyPayload proposal_append_only_payload = 3; - BlindVoteAppendOnlyPayload blind_vote_append_only_payload = 4; + ProposalPayload proposal_payload = 3; + BlindVotePayload blind_vote_payload = 4; } } @@ -886,9 +886,9 @@ message PersistableEnvelope { State state = 15; - ProposalAppendOnlyStore proposal_append_only_store = 16; - ProposalStore proposal_store = 17; - BlindVoteAppendOnlyStore blind_vote_append_only_store = 18; + ProposalStore proposal_store = 16; + TempProposalStore temp_proposal_store = 17; + BlindVoteStore blind_vote_store = 18; MyProposalList my_proposal_list = 19; BallotList ballot_list = 20; MyVoteList my_vote_list = 21; @@ -1401,24 +1401,24 @@ message RemoveAltcoinProposal { string currency_code = 1; } -message ProposalPayload { +message TempProposalPayload { Proposal proposal = 1; bytes owner_pub_key_encoded = 2; map extra_data = 3; } -message ProposalAppendOnlyPayload { +message ProposalPayload { Proposal proposal = 1; int64 date = 2; bytes block_hash = 3; bytes hash = 4; } -message ProposalAppendOnlyStore { - repeated ProposalAppendOnlyPayload items = 1; +message ProposalStore { + repeated ProposalPayload items = 1; } -message ProposalStore { +message TempProposalStore { repeated ProtectedStorageEntry items = 1; } @@ -1471,11 +1471,11 @@ message MyBlindVoteList { repeated BlindVote blind_vote = 1; } -message BlindVoteAppendOnlyStore { - repeated BlindVoteAppendOnlyPayload items = 1; +message BlindVoteStore { + repeated BlindVotePayload items = 1; } -message BlindVoteAppendOnlyPayload { +message BlindVotePayload { BlindVote blind_vote = 1; int64 date = 2; bytes hash = 3; From 640b960c4e708b36aa3f3bb1a8441fe2e94237ac Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 15 Jun 2018 17:33:34 +0200 Subject: [PATCH 41/73] Support merit (WIP) - Add issuance class - Replace issuanceBlockHeightMap with issuanceMap --- src/main/proto/pb.proto | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 4165be6..530e607 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1168,7 +1168,6 @@ message TradingPeer { int64 current_date = 14; } - /////////////////////////////////////////////////////////////////////////////////////////// // Dispute /////////////////////////////////////////////////////////////////////////////////////////// @@ -1283,6 +1282,7 @@ enum TxType { message TxInput { string connected_tx_output_tx_id = 1; int32 connected_tx_output_index = 2; + string pub_key = 3; } message TxOutput { @@ -1341,7 +1341,6 @@ message PubKeyScript { string hex = 5; } - // dao data message DaoPhase { @@ -1361,7 +1360,7 @@ message State { repeated Block blocks = 4; map tx_type_map = 5; map burnt_fee_map = 6; - map issuance_block_height_map = 7; + map issuance_map = 7; map unspent_tx_output_map = 8; map tx_output_type_map = 9; map spent_info_map = 10; @@ -1369,6 +1368,14 @@ message State { map param_change_by_block_height = 12; } +message Issuance { + TxOutput tx_output = 1; + int32 chainHeight = 2; + int64 amount = 3; + string inputPubKey = 4; + int64 date = 5; +} + message Proposal { string uid = 1; string name = 2; From a4dee4896d2083715d1c95fb26bf48684d710a56 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 19 Jun 2018 19:51:58 +0200 Subject: [PATCH 42/73] Add merit implementation --- src/main/proto/pb.proto | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 530e607..0884d13 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -893,7 +893,7 @@ message PersistableEnvelope { BallotList ballot_list = 20; MyVoteList my_vote_list = 21; MyBlindVoteList my_blind_vote_list = 22; - + MeritList merit_list = 23; } } @@ -1369,11 +1369,10 @@ message State { } message Issuance { - TxOutput tx_output = 1; - int32 chainHeight = 2; + string tx_id = 1; + int32 chain_height = 2; int64 amount = 3; - string inputPubKey = 4; - int64 date = 5; + string pub_key = 4; } message Proposal { @@ -1472,6 +1471,7 @@ message BlindVote { bytes encrypted_votes = 1; string tx_id = 2; int64 stake = 3; + bytes encrypted_merit_list = 4; } message MyBlindVoteList { @@ -1503,6 +1503,15 @@ message LongVote { uint64 value = 1; } +message Merit { + Issuance issuance = 1; + bytes signature = 2; +} + +message MeritList { + repeated Merit merit = 1; +} + /////////////////////////////////////////////////////////////////////////////////////////// // Misc /////////////////////////////////////////////////////////////////////////////////////////// From 29c3610ada6ed06568ef7c99a9c78d64a6ad8311 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Tue, 19 Jun 2018 12:20:10 +0200 Subject: [PATCH 43/73] Add lockup version --- src/main/java/bisq/common/app/Version.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/bisq/common/app/Version.java b/src/main/java/bisq/common/app/Version.java index 755d684..496bbb9 100644 --- a/src/main/java/bisq/common/app/Version.java +++ b/src/main/java/bisq/common/app/Version.java @@ -122,4 +122,5 @@ public static void printVersion() { public static final byte PROPOSAL = (byte) 0x01; public static final byte BLIND_VOTE_VERSION = (byte) 0x01; public static final byte VOTE_REVEAL_VERSION = (byte) 0x01; + public static final byte LOCKUP_VERSION = (byte) 0x01; } From b2e56e8f43d7cbf1224159dd6db71a416b7aab89 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Wed, 20 Jun 2018 13:11:32 +0200 Subject: [PATCH 44/73] Add locktime, unlock_block_height to protobuf --- src/main/proto/pb.proto | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 0884d13..7cb63ad 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1364,8 +1364,10 @@ message State { map unspent_tx_output_map = 8; map tx_output_type_map = 9; map spent_info_map = 10; - repeated Cycle cycles = 11; - map param_change_by_block_height = 12; + map lock_time_map = 11; + map unlock_block_height_map = 12; + repeated Cycle cycles = 13; + map param_change_by_block_height = 14; } message Issuance { From 1b176293d7aeb56fe9190757641867f59f6ec1da Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 29 Jun 2018 11:59:40 +0200 Subject: [PATCH 45/73] Update gradle files - Move mavenLocal on top to resolve local jars first - Comment out annotationProcessor and testAnnotationProcessor entries as they conflict with grpc build (don't know why). Complete project build works also without the annotationProcessor entries. - Comment out btcd-cli4j entries in dependencyVerification as they cause build failure. TODO investigate why... --- build.gradle | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ca72d5b..be89d43 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,7 @@ tasks.withType(JavaCompile) { } repositories { + mavenLocal() jcenter() maven { url 'https://jitpack.io' } } @@ -57,6 +58,6 @@ dependencies { compile 'commons-io:commons-io:2.4' compile 'org.apache.commons:commons-lang3:3.4' compileOnly 'org.projectlombok:lombok:1.16.16' - annotationProcessor 'org.projectlombok:lombok:1.16.16' + // annotationProcessor 'org.projectlombok:lombok:1.16.16' testCompile 'junit:junit:4.12' } From f19f031684e830ec36d95f381692ebe38c57562e Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 29 Jun 2018 12:00:30 +0200 Subject: [PATCH 46/73] Add options to DevEnv. Cleanup --- src/main/java/bisq/common/UserThread.java | 2 -- src/main/java/bisq/common/app/DevEnv.java | 10 ++++++++++ src/main/proto/pb.proto | 2 -- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/bisq/common/UserThread.java b/src/main/java/bisq/common/UserThread.java index b4d52d6..2b28c95 100644 --- a/src/main/java/bisq/common/UserThread.java +++ b/src/main/java/bisq/common/UserThread.java @@ -58,12 +58,10 @@ public static void setTimerClass(Class timerClass) { timerClass = FrameRateTimer.class; } - public static void execute(Runnable command) { UserThread.executor.execute(command); } - // Prefer FxTimer if a delay is needed in a JavaFx class (gui module) public static Timer runAfterRandomDelay(Runnable runnable, long minDelayInSec, long maxDelayInSec) { return UserThread.runAfterRandomDelay(runnable, minDelayInSec, maxDelayInSec, TimeUnit.SECONDS); diff --git a/src/main/java/bisq/common/app/DevEnv.java b/src/main/java/bisq/common/app/DevEnv.java index c74c8b4..30e8f64 100644 --- a/src/main/java/bisq/common/app/DevEnv.java +++ b/src/main/java/bisq/common/app/DevEnv.java @@ -17,10 +17,20 @@ package bisq.common.app; +import bisq.common.CommonOptionKeys; + +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.name.Names; + import lombok.extern.slf4j.Slf4j; @Slf4j public class DevEnv { + public static void setup(Injector injector) { + DevEnv.setDevMode(injector.getInstance(Key.get(Boolean.class, Names.named(CommonOptionKeys.USE_DEV_MODE)))); + } + // The UI got set the private dev key so the developer does not need to do anything and can test those features. // Features: Arbitration registration (alt+R at account), Alert/Update (alt+m), private message to a // peer (click user icon and alt+r), filter/block offers by various data like offer ID (cmd + f). diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 7f55607..6263854 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -901,9 +901,7 @@ message PersistableEnvelope { PersistableNetworkPayloadList persistable_network_payload_list = 12; // deprecated. Not used anymore. AccountAgeWitnessStore account_age_witness_store = 13; TradeStatistics2Store trade_statistics2_store = 14; - State state = 15; - ProposalStore proposal_store = 16; TempProposalStore temp_proposal_store = 17; BlindVoteStore blind_vote_store = 18; From 197e6e4d64ce2f9f6eab39711eb2696878b38914 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 29 Jun 2018 23:27:04 +0200 Subject: [PATCH 47/73] Refactor mutable data handling in State The data handling with flat maps for each type of mutable data as we used before feels very un-intuitive to use. This commit changes the flat map to a tree structure. We use a map of mutableTx objects. The mutableTx contains the immutable Tx and a map of mutableTxOutputs as well as mutable fields like type. The mutableTxOutput contains an immutable TxOutput and mutable fields like type. That commit might have broken something in the bonding. Should be fixed in updates... --- src/main/proto/pb.proto | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 6263854..b23151b 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1281,6 +1281,15 @@ message Tx { repeated TxOutput outputs = 7; } +message MutableTx { + Tx tx = 1; + TxType txType = 2; + map mutable_tx_outputs = 3; + int64 burnt_fee = 4; + int32 lock_time = 5; + int32 unlock_block_height = 6; +} + enum TxType { PB_ERROR_TX_TYPE = 0; UNDEFINED_TX_TYPE = 1; @@ -1313,6 +1322,12 @@ message TxOutput { int32 block_height = 7; } +message MutableTxOutput { + TxOutput tx_output = 1; + TxOutputType tx_output_type = 2; + bool is_unspent = 3; +} + enum TxOutputType { PB_ERROR_TX_OUTPUT_TYPE = 0; UNDEFINED = 1; @@ -1376,16 +1391,11 @@ message State { int32 genesis_block_height = 2; int32 chain_height = 3; repeated Block blocks = 4; - map tx_type_map = 5; - map burnt_fee_map = 6; - map issuance_map = 7; - map unspent_tx_output_map = 8; - map tx_output_type_map = 9; - map spent_info_map = 10; - map lock_time_map = 11; - map unlock_block_height_map = 12; - repeated Cycle cycles = 13; - map param_change_by_block_height = 14; + repeated Cycle cycles = 5; + map mutable_tx_map = 6; + map spent_info_map = 7; + map issuance_map = 8; + map param_change_by_block_height = 9; } message Issuance { From 6dd6e0fe1ffa57d0479cd9d93ddb0618b9d37c94 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 7 Jul 2018 15:24:20 +0200 Subject: [PATCH 48/73] Refactor MutableTx and MutableTxOutput We renamed Tx to RawTx and MutableTx to Tx and moved it to bisq.core.dao.state.blockchain. Same with MutableTxOutput... --- src/main/proto/pb.proto | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index b23151b..aea1995 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -309,12 +309,12 @@ message GetBlocksRequest { } message GetBlocksResponse { - repeated Block blocks = 1; + repeated RawBlock raw_blocks = 1; int32 request_nonce = 2; } message NewBlockBroadcastMessage { - Block block = 1; + RawBlock raw_block = 1; } /////////////////////////////////////////////////////////////////////////////////////////// @@ -1263,6 +1263,14 @@ message UserPayload { // blockchain +message RawBlock { + int32 height = 1; + int64 time = 2; + string hash = 3; + string previous_block_hash = 4; + repeated RawTx raw_txs = 5; +} + message Block { int32 height = 1; int64 time = 2; @@ -1271,20 +1279,20 @@ message Block { repeated Tx txs = 5; } -message Tx { +message RawTx { string tx_version = 1; string id = 2; int32 block_height = 3; string block_hash = 4; int64 time = 5; - repeated TxInput inputs = 6; - repeated TxOutput outputs = 7; + repeated TxInput tx_inputs = 6; + repeated RawTxOutput raw_tx_outputs = 7; } -message MutableTx { - Tx tx = 1; +message Tx { + RawTx tx = 1; TxType txType = 2; - map mutable_tx_outputs = 3; + repeated TxOutput tx_outputs = 3; int64 burnt_fee = 4; int32 lock_time = 5; int32 unlock_block_height = 6; @@ -1312,7 +1320,7 @@ message TxInput { string pub_key = 3; } -message TxOutput { +message RawTxOutput { int32 index = 1; int64 value = 2; string tx_id = 3; @@ -1322,8 +1330,8 @@ message TxOutput { int32 block_height = 7; } -message MutableTxOutput { - TxOutput tx_output = 1; +message TxOutput { + RawTxOutput raw_tx_output = 1; TxOutputType tx_output_type = 2; bool is_unspent = 3; } @@ -1392,7 +1400,7 @@ message State { int32 chain_height = 3; repeated Block blocks = 4; repeated Cycle cycles = 5; - map mutable_tx_map = 6; + map tx_map = 6; //TODO remove map spent_info_map = 7; map issuance_map = 8; map param_change_by_block_height = 9; From 4208514148e15b2da030a962e1683b54fd57de6f Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 7 Jul 2018 18:57:03 +0200 Subject: [PATCH 49/73] Apply fixes to stateService --- src/main/proto/pb.proto | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index aea1995..b1c41d8 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1333,7 +1333,6 @@ message RawTxOutput { message TxOutput { RawTxOutput raw_tx_output = 1; TxOutputType tx_output_type = 2; - bool is_unspent = 3; } enum TxOutputType { @@ -1400,7 +1399,7 @@ message State { int32 chain_height = 3; repeated Block blocks = 4; repeated Cycle cycles = 5; - map tx_map = 6; //TODO remove + map unspent_tx_output_map = 6; map spent_info_map = 7; map issuance_map = 8; map param_change_by_block_height = 9; From ccc5340238f4a14c4a1e2f622811296acbebb584 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 8 Jul 2018 21:14:25 +0200 Subject: [PATCH 50/73] Remove date and blockHash from ProposalPayload We vote on non-existing ProposalPayload with a negative vote. That is an easier protection with less complexity. --- src/main/proto/pb.proto | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index b1c41d8..0095d6e 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1452,9 +1452,7 @@ message TempProposalPayload { message ProposalPayload { Proposal proposal = 1; - int64 date = 2; - bytes block_hash = 3; - bytes hash = 4; + bytes hash = 2; } message ProposalStore { From 950bf712e0896f24fd2e8b1a293a2796c5c13710 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 9 Jul 2018 21:30:00 +0200 Subject: [PATCH 51/73] Use name instead of ordinal for PB ParamChangeMap --- src/main/proto/pb.proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 0095d6e..46fdf4f 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1477,7 +1477,7 @@ message BallotList { } message ParamChangeMap { - map map = 1; + map map = 1; // key is enum name, value is paramValue as long } message MyVote { From 71075d04ebcf8f97abbe21ecdb35099d1393fba0 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 9 Jul 2018 22:13:52 +0200 Subject: [PATCH 52/73] Add param request --- src/main/java/bisq/common/app/Version.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/bisq/common/app/Version.java b/src/main/java/bisq/common/app/Version.java index 496bbb9..890878f 100644 --- a/src/main/java/bisq/common/app/Version.java +++ b/src/main/java/bisq/common/app/Version.java @@ -118,6 +118,7 @@ public static void printVersion() { '}'); } + //TODO rename public static final byte COMPENSATION_REQUEST_VERSION = (byte) 0x01; public static final byte PROPOSAL = (byte) 0x01; public static final byte BLIND_VOTE_VERSION = (byte) 0x01; From bf413d51e55caf0f355ce1bc36b2f8d3d0affab1 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 9 Jul 2018 22:14:21 +0200 Subject: [PATCH 53/73] Rename --- src/main/java/bisq/common/app/Version.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/bisq/common/app/Version.java b/src/main/java/bisq/common/app/Version.java index 890878f..44d8151 100644 --- a/src/main/java/bisq/common/app/Version.java +++ b/src/main/java/bisq/common/app/Version.java @@ -118,10 +118,9 @@ public static void printVersion() { '}'); } - //TODO rename - public static final byte COMPENSATION_REQUEST_VERSION = (byte) 0x01; + public static final byte COMPENSATION_REQUEST = (byte) 0x01; public static final byte PROPOSAL = (byte) 0x01; - public static final byte BLIND_VOTE_VERSION = (byte) 0x01; - public static final byte VOTE_REVEAL_VERSION = (byte) 0x01; - public static final byte LOCKUP_VERSION = (byte) 0x01; + public static final byte BLIND_VOTE = (byte) 0x01; + public static final byte VOTE_REVEAL = (byte) 0x01; + public static final byte LOCKUP = (byte) 0x01; } From b52cc3ccdb3b13de7aec98886c0a88918ecb122d Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 9 Jul 2018 22:21:26 +0200 Subject: [PATCH 54/73] Add PB support for changeParamProposal --- src/main/proto/pb.proto | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 46fdf4f..c0e88ca 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1438,6 +1438,8 @@ message GenericProposal { } message ChangeParamProposal { + string param = 1; // name of enum + int64 param_value = 2; } message RemoveAltcoinProposal { From 75680f10f551b8bab8657046699a4275dffb8d49 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 10 Jul 2018 01:23:40 +0200 Subject: [PATCH 55/73] Change param map in state --- src/main/proto/pb.proto | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index c0e88ca..78c12a1 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1402,7 +1402,7 @@ message State { map unspent_tx_output_map = 6; map spent_info_map = 7; map issuance_map = 8; - map param_change_by_block_height = 9; + repeated ParamChange param_change_list = 9; } message Issuance { @@ -1478,8 +1478,10 @@ message BallotList { repeated Ballot ballot = 1; } -message ParamChangeMap { - map map = 1; // key is enum name, value is paramValue as long +message ParamChange { + string param_name = 1; + int64 param_value = 2; + int32 activation_height = 3; } message MyVote { From e564778efe1116f61a367c694c903fc5784f9ea9 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Fri, 13 Jul 2018 00:15:19 +0200 Subject: [PATCH 56/73] Show bond info, cleanups, handle non-BSQ funds --- src/main/proto/pb.proto | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 40d9cef..83bb6a2 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1406,9 +1406,11 @@ message State { repeated Block blocks = 4; repeated Cycle cycles = 5; map unspent_tx_output_map = 6; - map spent_info_map = 7; - map issuance_map = 8; - repeated ParamChange param_change_list = 9; + map non_bsq_tx_output_map = 7; + map confiscated_tx_output_map = 8; + map spent_info_map = 9; + map issuance_map = 10; + repeated ParamChange param_change_list = 11; } message Issuance { From 239484b9a7d020389ffc7648f7300e8d61a8047e Mon Sep 17 00:00:00 2001 From: sqrrm Date: Wed, 18 Jul 2018 23:11:05 +0200 Subject: [PATCH 57/73] Add burn bond proposal --- src/main/proto/pb.proto | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 83bb6a2..e8c01fd 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1434,6 +1434,7 @@ message Proposal { GenericProposal generic_proposal = 10; ChangeParamProposal change_param_proposal = 11; RemoveAltcoinProposal remove_altcoin_proposal = 12; + BurnBondProposal burn_bond_proposal = 13; } } @@ -1454,6 +1455,10 @@ message RemoveAltcoinProposal { string currency_code = 1; } +message BurnBondProposal { + string bond_id = 1; +} + message TempProposalPayload { Proposal proposal = 1; bytes owner_pub_key_encoded = 2; From bb702d26366c2accc8552647635533db0d052f72 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sat, 21 Jul 2018 19:49:06 +0200 Subject: [PATCH 58/73] Burn bonds when proposal is accepted Add bond id for bonds tied to role. Currently as a manual field to test things out. Should be some kind of automatically generated hash eventually. --- src/main/proto/pb.proto | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index e8c01fd..8d31362 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1456,7 +1456,7 @@ message RemoveAltcoinProposal { } message BurnBondProposal { - string bond_id = 1; + bytes bond_id = 1; } message TempProposalPayload { @@ -1497,6 +1497,11 @@ message ParamChange { int32 activation_height = 3; } +message BurnBond { + bytes bond_id = 1; + int32 activation_height = 2; +} + message MyVote { int32 height = 1; BallotList ballot_list = 2; From 84be2564b0bec5d03fda42b43bd81545bc8af500 Mon Sep 17 00:00:00 2001 From: sqrrm Date: Sat, 21 Jul 2018 20:29:27 +0200 Subject: [PATCH 59/73] Rename burn bond to confiscate bond --- src/main/proto/pb.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 8d31362..1fa6a33 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1434,7 +1434,7 @@ message Proposal { GenericProposal generic_proposal = 10; ChangeParamProposal change_param_proposal = 11; RemoveAltcoinProposal remove_altcoin_proposal = 12; - BurnBondProposal burn_bond_proposal = 13; + ConfiscateBondProposal confiscate_bond_proposal = 13; } } @@ -1455,7 +1455,7 @@ message RemoveAltcoinProposal { string currency_code = 1; } -message BurnBondProposal { +message ConfiscateBondProposal { bytes bond_id = 1; } @@ -1497,7 +1497,7 @@ message ParamChange { int32 activation_height = 3; } -message BurnBond { +message ConfiscateBond { bytes bond_id = 1; int32 activation_height = 2; } From 92778a21f2789513174cd86f79b4a6a02e462d41 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 22 Jul 2018 00:12:20 +0200 Subject: [PATCH 60/73] Changes from review of bond confiscation PR --- src/main/proto/pb.proto | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 1fa6a33..6f8e8cf 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1456,7 +1456,7 @@ message RemoveAltcoinProposal { } message ConfiscateBondProposal { - bytes bond_id = 1; + bytes hash_of_bond_id = 1; } message TempProposalPayload { @@ -1498,8 +1498,8 @@ message ParamChange { } message ConfiscateBond { - bytes bond_id = 1; - int32 activation_height = 2; + bytes hash_of_bond_id = 1; + int32 activation_height = 2; //TODO needed? } message MyVote { From 928e5f9b30998a4340ed0786a73a226d75f73fca Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 23 Jul 2018 02:22:18 +0200 Subject: [PATCH 61/73] Add BondedRoles proposal and views --- .../java/bisq/common/storage/Storage.java | 3 +++ src/main/java/bisq/common/util/Utilities.java | 17 ++++++++++++ src/main/proto/pb.proto | 25 ++++++++++++++++-- .../java/bisq/common/util/UtilitiesTest.java | 26 +++++++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/main/java/bisq/common/storage/Storage.java b/src/main/java/bisq/common/storage/Storage.java index 0ddac59..17c4164 100644 --- a/src/main/java/bisq/common/storage/Storage.java +++ b/src/main/java/bisq/common/storage/Storage.java @@ -17,6 +17,7 @@ package bisq.common.storage; +import bisq.common.app.DevEnv; import bisq.common.proto.persistable.PersistableEnvelope; import bisq.common.proto.persistable.PersistenceProtoResolver; @@ -165,6 +166,8 @@ private T getPersisted() { try { // We keep a backup which might be used for recovery fileManager.removeAndBackupFile(fileName); + if (DevEnv.isDevMode()) + throw new RuntimeException(t); } catch (IOException e1) { e1.printStackTrace(); log.error(e1.getMessage()); diff --git a/src/main/java/bisq/common/util/Utilities.java b/src/main/java/bisq/common/util/Utilities.java index bcc6fa1..296d026 100644 --- a/src/main/java/bisq/common/util/Utilities.java +++ b/src/main/java/bisq/common/util/Utilities.java @@ -603,4 +603,21 @@ public static boolean isRestrictedCryptography() { return name != null && name.equals("Java(TM) SE Runtime Environment") && ver != null && (ver.startsWith("1.7") || ver.startsWith("1.8")); } + + public static byte[] integerToByteArray(int intValue, int numBytes) { + byte[] bytes = new byte[numBytes]; + for (int i = numBytes - 1; i >= 0; i--) { + bytes[i] = ((byte) (intValue & 0xFF)); + intValue >>>= 8; + } + return bytes; + } + + public static int byteArrayToInteger(byte[] bytes) { + int result = 0; + for (byte aByte : bytes) { + result = result << 8 | aByte & 0xff; + } + return result; + } } diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 6f8e8cf..c8bf573 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -916,6 +916,7 @@ message PersistableEnvelope { MyVoteList my_vote_list = 21; MyBlindVoteList my_blind_vote_list = 22; MeritList merit_list = 23; + BondedRoleList bonded_role_list = 24; } } @@ -1435,6 +1436,7 @@ message Proposal { ChangeParamProposal change_param_proposal = 11; RemoveAltcoinProposal remove_altcoin_proposal = 12; ConfiscateBondProposal confiscate_bond_proposal = 13; + BondedRoleProposal bonded_role_proposal = 14; } } @@ -1456,7 +1458,26 @@ message RemoveAltcoinProposal { } message ConfiscateBondProposal { - bytes hash_of_bond_id = 1; + bytes hash = 1; +} + +message BondedRoleProposal { + BondedRole bonded_role = 1; +} + +message BondedRole { + string uid = 1; + string name = 2; + string link_to_account = 3; + string bonded_role_type = 4; // name of BondedRoleType enum + uint64 start_date = 5; + string lockup_tx_id = 6; + uint64 revoke_date = 7; + string unlock_tx_id = 8; +} + +message BondedRoleList { + repeated BondedRole bonded_role = 1; } message TempProposalPayload { @@ -1498,7 +1519,7 @@ message ParamChange { } message ConfiscateBond { - bytes hash_of_bond_id = 1; + bytes hash = 1; int32 activation_height = 2; //TODO needed? } diff --git a/src/test/java/bisq/common/util/UtilitiesTest.java b/src/test/java/bisq/common/util/UtilitiesTest.java index ee19330..22dab34 100644 --- a/src/test/java/bisq/common/util/UtilitiesTest.java +++ b/src/test/java/bisq/common/util/UtilitiesTest.java @@ -52,4 +52,30 @@ public void testToStringList() { assertEquals(1, Utilities.commaSeparatedListToSet("test1", false).size()); assertEquals(2, Utilities.commaSeparatedListToSet("test1, test2", false).size()); } + + @Test + public void testIntegerToByteArray() { + assertEquals("0000", Utilities.bytesAsHexString(Utilities.integerToByteArray(0, 2))); + assertEquals("ffff", Utilities.bytesAsHexString(Utilities.integerToByteArray(65535, 2))); + assertEquals("0011", Utilities.bytesAsHexString(Utilities.integerToByteArray(17, 2))); + assertEquals("1100", Utilities.bytesAsHexString(Utilities.integerToByteArray(4352, 2))); + assertEquals("dd22", Utilities.bytesAsHexString(Utilities.integerToByteArray(56610, 2))); + assertEquals("7fffffff", Utilities.bytesAsHexString(Utilities.integerToByteArray(2147483647, 4))); // Integer.MAX_VALUE + assertEquals("80000000", Utilities.bytesAsHexString(Utilities.integerToByteArray(-2147483648, 4))); // Integer.MIN_VALUE + assertEquals("00110011", Utilities.bytesAsHexString(Utilities.integerToByteArray(1114129, 4))); + assertEquals("ffeeffef", Utilities.bytesAsHexString(Utilities.integerToByteArray(-1114129, 4))); + } + + @Test + public void testByteArrayToInteger() { + assertEquals(0, Utilities.byteArrayToInteger(Utilities.decodeFromHex("0000"))); + assertEquals(65535, Utilities.byteArrayToInteger(Utilities.decodeFromHex("ffff"))); + assertEquals(4352, Utilities.byteArrayToInteger(Utilities.decodeFromHex("1100"))); + assertEquals(17, Utilities.byteArrayToInteger(Utilities.decodeFromHex("0011"))); + assertEquals(56610, Utilities.byteArrayToInteger(Utilities.decodeFromHex("dd22"))); + assertEquals(2147483647, Utilities.byteArrayToInteger(Utilities.decodeFromHex("7fffffff"))); + assertEquals(-2147483648, Utilities.byteArrayToInteger(Utilities.decodeFromHex("80000000"))); + assertEquals(1114129, Utilities.byteArrayToInteger(Utilities.decodeFromHex("00110011"))); + assertEquals(-1114129, Utilities.byteArrayToInteger(Utilities.decodeFromHex("ffeeffef"))); + } } From c399c057ab501ae2778512bde4e56a886cda569d Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 23 Jul 2018 13:56:21 +0200 Subject: [PATCH 62/73] Add EqualsAndHashCode to PersistableLists - fix row display in proposal display --- .../java/bisq/common/proto/persistable/PersistableList.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/bisq/common/proto/persistable/PersistableList.java b/src/main/java/bisq/common/proto/persistable/PersistableList.java index 9632a33..65cd108 100644 --- a/src/main/java/bisq/common/proto/persistable/PersistableList.java +++ b/src/main/java/bisq/common/proto/persistable/PersistableList.java @@ -25,10 +25,12 @@ import java.util.function.Function; import java.util.stream.Stream; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.experimental.Delegate; +@EqualsAndHashCode public class PersistableList implements PersistableEnvelope, Iterable { @Delegate(excludes = ExcludesDelegateMethods.class) @Getter From 57a3fa9fa16b6b5bdc03b8fdf1e374f9726a6c65 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 25 Jul 2018 13:10:12 +0200 Subject: [PATCH 63/73] Remvoe title and description from Proposal --- src/main/proto/pb.proto | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index f7dd28f..c0d3d55 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1431,19 +1431,17 @@ message Issuance { message Proposal { string uid = 1; string name = 2; - string title = 3; - string description = 4; - string link = 5; - uint32 version = 6; - int64 creation_date = 7; - string tx_id = 8; + string link = 3; + uint32 version = 4; + int64 creation_date = 5; + string tx_id = 6; oneof message { - CompensationProposal compensation_proposal = 9; - GenericProposal generic_proposal = 10; - ChangeParamProposal change_param_proposal = 11; - RemoveAltcoinProposal remove_altcoin_proposal = 12; - ConfiscateBondProposal confiscate_bond_proposal = 13; - BondedRoleProposal bonded_role_proposal = 14; + CompensationProposal compensation_proposal = 7; + GenericProposal generic_proposal = 8; + ChangeParamProposal change_param_proposal = 9; + RemoveAltcoinProposal remove_altcoin_proposal = 10; + ConfiscateBondProposal confiscate_bond_proposal = 11; + BondedRoleProposal bonded_role_proposal = 12; } } @@ -1475,7 +1473,7 @@ message BondedRoleProposal { message BondedRole { string uid = 1; string name = 2; - string link_to_account = 3; + string link = 3; string bonded_role_type = 4; // name of BondedRoleType enum uint64 start_date = 5; string lockup_tx_id = 6; From bd9cb153bf5c8e5d6e9432b12a1e945f35211f7b Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 6 Aug 2018 14:03:20 +0200 Subject: [PATCH 64/73] Update BsqState in PB, reorder fields --- src/main/proto/pb.proto | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index c0d3d55..bee0cb2 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -908,7 +908,7 @@ message PersistableEnvelope { AccountAgeWitnessStore account_age_witness_store = 12; TradeStatistics2Store trade_statistics2_store = 13; - State state = 14; + BsqState bsq_state = 14; // we need to keep id 15 here otherwise the reading of the old data structure would not work anymore. // can be removed after most people have updated as the reading of the PersistableNetworkPayloadList @@ -1407,7 +1407,7 @@ message Cycle { repeated DaoPhase dao_phase = 2; } -message State { +message BsqState { string genesis_tx_id = 1; int32 genesis_block_height = 2; int32 chain_height = 3; @@ -1415,9 +1415,9 @@ message State { repeated Cycle cycles = 5; map unspent_tx_output_map = 6; map non_bsq_tx_output_map = 7; - map confiscated_tx_output_map = 8; - map spent_info_map = 9; - map issuance_map = 10; + map issuance_map = 8; + map confiscated_tx_output_map = 9; + map spent_info_map = 10; repeated ParamChange param_change_list = 11; } From 81db1de47fab93d84c1e68dfaa11cdffd20412e7 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 6 Aug 2018 16:47:49 +0200 Subject: [PATCH 65/73] Refactor Tx classes - Add BaseTx class containing only immutable blockchain-only data which is common in sub classes - RawTx extends BaseTx - TempTx extends BaseTx and has mutable data which can be altered during tx parsing. TempTx is only used during parsing and gets converted to teh immutable Tx when tx parsing is completed. - Tx extends BaseTx and is immutable and used to be stored in the Block. --- .../java/bisq/common/proto/ProtoUtil.java | 4 +-- src/main/proto/pb.proto | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/bisq/common/proto/ProtoUtil.java b/src/main/java/bisq/common/proto/ProtoUtil.java index 0237229..6f9f1f1 100644 --- a/src/main/java/bisq/common/proto/ProtoUtil.java +++ b/src/main/java/bisq/common/proto/ProtoUtil.java @@ -64,11 +64,11 @@ public static byte[] byteArrayOrNullFromProto(ByteString proto) { * @param the enum Type * @return an enum */ + @Nullable public static > E enumFromProto(Class enumType, String name) { E result = Enums.getIfPresent(enumType, name).orNull(); - if (result == null) { + if (result == null) log.error("Invalid value for enum " + enumType.getSimpleName() + ": " + name); - } return result; } diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index bee0cb2..ff837e4 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1276,13 +1276,12 @@ message UserPayload { /////////////////////////////////////////////////////////////////////////////////////////// // blockchain - message RawBlock { int32 height = 1; int64 time = 2; string hash = 3; string previous_block_hash = 4; - repeated RawTx raw_txs = 5; + repeated BaseTx raw_txs = 5; } message Block { @@ -1290,26 +1289,32 @@ message Block { int64 time = 2; string hash = 3; string previous_block_hash = 4; - repeated Tx txs = 5; + repeated BaseTx txs = 5; } -message RawTx { +message BaseTx { string tx_version = 1; string id = 2; int32 block_height = 3; string block_hash = 4; int64 time = 5; repeated TxInput tx_inputs = 6; - repeated RawTxOutput raw_tx_outputs = 7; + oneof message { + RawTx raw_tx = 7; + Tx tx = 8; + } +} + +message RawTx { + repeated RawTxOutput raw_tx_outputs = 1; } message Tx { - RawTx tx = 1; + repeated TxOutput tx_outputs = 1; TxType txType = 2; - repeated TxOutput tx_outputs = 3; - int64 burnt_fee = 4; - int32 lock_time = 5; - int32 unlock_block_height = 6; + int64 burnt_fee = 3; + int32 lock_time = 4; + int32 unlock_block_height = 5; } enum TxType { From d278067636cdb65d3a427305c7adc45721940ef3 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 6 Aug 2018 19:53:38 +0200 Subject: [PATCH 66/73] Refactor TxOutput and Block classes - Add BaseTxOutput and BaseBlock class containing only immutable blockchain-only data which is common in sub classes - RawTxOutput extends BaseTxOutput, RawBlock extends BaseBlock - TempTxOutput extends BaseTxOutput and has mutable data which can be altered during tx parsing. TempTxOutput is only used during parsing and gets converted to the immutable TxOutput when tx parsing is completed. - TxOutput extends BaseTx and is immutable and used to be stored in the Block. - Block extends BaseBlock and is persisted with the BsqState. The tx list is not a immutable list bu the transactions in there are immutable. Transactions gets added during parsing to the block which was gets added to the BsqState when parsing starts. - Change block time from seconds to ms --- src/main/proto/pb.proto | 54 +++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 18 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index ff837e4..e754972 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -309,12 +309,14 @@ message GetBlocksRequest { } message GetBlocksResponse { - repeated RawBlock raw_blocks = 1; + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseBlock raw_blocks = 1; int32 request_nonce = 2; } message NewBlockBroadcastMessage { - RawBlock raw_block = 1; + // Because of the way how PB implements inheritence we need to use the super class as type + BaseBlock raw_block = 1; } /////////////////////////////////////////////////////////////////////////////////////////// @@ -1276,20 +1278,26 @@ message UserPayload { /////////////////////////////////////////////////////////////////////////////////////////// // blockchain -message RawBlock { + +message BaseBlock { int32 height = 1; int64 time = 2; string hash = 3; string previous_block_hash = 4; - repeated BaseTx raw_txs = 5; + oneof message { + RawBlock raw_block = 5; + Block block = 6; + } +} + +message RawBlock { + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseTx raw_txs = 1; } message Block { - int32 height = 1; - int64 time = 2; - string hash = 3; - string previous_block_hash = 4; - repeated BaseTx txs = 5; + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseTx txs = 1; } message BaseTx { @@ -1306,11 +1314,13 @@ message BaseTx { } message RawTx { - repeated RawTxOutput raw_tx_outputs = 1; + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseTxOutput raw_tx_outputs = 1; } message Tx { - repeated TxOutput tx_outputs = 1; + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseTxOutput tx_outputs = 1; TxType txType = 2; int64 burnt_fee = 3; int32 lock_time = 4; @@ -1339,7 +1349,7 @@ message TxInput { string pub_key = 3; } -message RawTxOutput { +message BaseTxOutput { int32 index = 1; int64 value = 2; string tx_id = 3; @@ -1347,11 +1357,17 @@ message RawTxOutput { string address = 5; bytes op_return_data = 6; int32 block_height = 7; + oneof message { + RawTxOutput raw_tx_output = 8; + TxOutput tx_output = 9; + } +} + +message RawTxOutput { } message TxOutput { - RawTxOutput raw_tx_output = 1; - TxOutputType tx_output_type = 2; + TxOutputType tx_output_type = 1; } enum TxOutputType { @@ -1416,12 +1432,14 @@ message BsqState { string genesis_tx_id = 1; int32 genesis_block_height = 2; int32 chain_height = 3; - repeated Block blocks = 4; + // Because of the way how PB implements inheritence we need to use the super class as type + repeated BaseBlock blocks = 4; repeated Cycle cycles = 5; - map unspent_tx_output_map = 6; - map non_bsq_tx_output_map = 7; + // Because of the way how PB implements inheritence we need to use the super class as type + map unspent_tx_output_map = 6; + map non_bsq_tx_output_map = 7; map issuance_map = 8; - map confiscated_tx_output_map = 9; + map confiscated_tx_output_map = 9; map spent_info_map = 10; repeated ParamChange param_change_list = 11; } From f05a1b0c189ea74facbc87ac5e3a4212faeabe36 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Tue, 7 Aug 2018 13:34:05 +0200 Subject: [PATCH 67/73] Refactoring - Rename bisq.core.dao.state.ext package to bisq.core.dao.state.governance --- src/main/proto/pb.proto | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index e754972..e3a4861 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1548,7 +1548,6 @@ message ParamChange { message ConfiscateBond { bytes hash = 1; - int32 activation_height = 2; //TODO needed? } message MyVote { From fa31c113029f41b89a71bd57a4b6b919fb7fcda8 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 8 Aug 2018 22:54:54 +0200 Subject: [PATCH 68/73] Use DevEnv.logErrorAndThrowIfDevMode --- src/main/java/bisq/common/storage/Storage.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/bisq/common/storage/Storage.java b/src/main/java/bisq/common/storage/Storage.java index 17c4164..0b15a32 100644 --- a/src/main/java/bisq/common/storage/Storage.java +++ b/src/main/java/bisq/common/storage/Storage.java @@ -166,8 +166,7 @@ private T getPersisted() { try { // We keep a backup which might be used for recovery fileManager.removeAndBackupFile(fileName); - if (DevEnv.isDevMode()) - throw new RuntimeException(t); + DevEnv.logErrorAndThrowIfDevMode(t.toString()); } catch (IOException e1) { e1.printStackTrace(); log.error(e1.getMessage()); From c1dee682c2ca3d7fbd999d9fe6a0ad14937ec38a Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 8 Aug 2018 23:40:18 +0200 Subject: [PATCH 69/73] Remove uid from Proposal We can use the txId as unique ID --- src/main/proto/pb.proto | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index e3a4861..2c4e6d4 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1452,19 +1452,18 @@ message Issuance { } message Proposal { - string uid = 1; - string name = 2; - string link = 3; - uint32 version = 4; - int64 creation_date = 5; - string tx_id = 6; + string name = 1; + string link = 2; + uint32 version = 3; + int64 creation_date = 4; + string tx_id = 5; oneof message { - CompensationProposal compensation_proposal = 7; - GenericProposal generic_proposal = 8; - ChangeParamProposal change_param_proposal = 9; - RemoveAltcoinProposal remove_altcoin_proposal = 10; - ConfiscateBondProposal confiscate_bond_proposal = 11; - BondedRoleProposal bonded_role_proposal = 12; + CompensationProposal compensation_proposal = 6; + GenericProposal generic_proposal = 7; + ChangeParamProposal change_param_proposal = 8; + RemoveAltcoinProposal remove_altcoin_proposal = 9; + ConfiscateBondProposal confiscate_bond_proposal = 10; + BondedRoleProposal bonded_role_proposal = 11; } } From 5d35af99f8df8f4a7aa6ab5c078b66c8f9cabcc7 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 9 Aug 2018 00:54:45 +0200 Subject: [PATCH 70/73] Remove BooleanVote and LongVote. Make Vote to BooleanVote --- src/main/proto/pb.proto | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index 2c4e6d4..ba2b9f1 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1593,20 +1593,9 @@ message BlindVotePayload { } message Vote { - oneof message { - BooleanVote boolean_vote = 1; - LongVote long_vote = 2; - } -} - -message BooleanVote { bool accepted = 1; } -message LongVote { - uint64 value = 1; -} - message Merit { Issuance issuance = 1; bytes signature = 2; From 06b9370bdebe442dbf343ceaf40f5d54f647c21f Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 9 Aug 2018 14:15:00 +0200 Subject: [PATCH 71/73] Change version from -SNAPSHOT to 0.9.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index be89d43..c1c21a7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'network.bisq' -version = '-SNAPSHOT' +version = '0.9.0' ext { protobufVersion = '3.5.1' From 6e2fee19419ad23175745fa6d5133e30c3af9b78 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sat, 11 Aug 2018 12:44:11 +0200 Subject: [PATCH 72/73] Move genesis data from BsqState to GenesisTxInfo --- src/main/proto/pb.proto | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/proto/pb.proto b/src/main/proto/pb.proto index ba2b9f1..d7c603e 100644 --- a/src/main/proto/pb.proto +++ b/src/main/proto/pb.proto @@ -1429,19 +1429,17 @@ message Cycle { } message BsqState { - string genesis_tx_id = 1; - int32 genesis_block_height = 2; - int32 chain_height = 3; + int32 chain_height = 1; // Because of the way how PB implements inheritence we need to use the super class as type - repeated BaseBlock blocks = 4; - repeated Cycle cycles = 5; + repeated BaseBlock blocks = 2; + repeated Cycle cycles = 3; // Because of the way how PB implements inheritence we need to use the super class as type - map unspent_tx_output_map = 6; - map non_bsq_tx_output_map = 7; - map issuance_map = 8; - map confiscated_tx_output_map = 9; - map spent_info_map = 10; - repeated ParamChange param_change_list = 11; + map unspent_tx_output_map = 4; + map non_bsq_tx_output_map = 5; + map issuance_map = 6; + map confiscated_tx_output_map = 7; + map spent_info_map = 8; + repeated ParamChange param_change_list = 9; } message Issuance { From 89ff8fa8c6ad1571c182b521eff767f1f1f35fba Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Wed, 15 Aug 2018 00:14:22 +0200 Subject: [PATCH 73/73] Merge branch 'master' into voting # Conflicts: # src/main/resources/i18n/displayStrings.properties Merge branch 'master' into voting # Conflicts: # build.gradle --- build.gradle | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index c1c21a7..ca72d5b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'network.bisq' -version = '0.9.0' +version = '-SNAPSHOT' ext { protobufVersion = '3.5.1' @@ -18,7 +18,6 @@ tasks.withType(JavaCompile) { } repositories { - mavenLocal() jcenter() maven { url 'https://jitpack.io' } } @@ -58,6 +57,6 @@ dependencies { compile 'commons-io:commons-io:2.4' compile 'org.apache.commons:commons-lang3:3.4' compileOnly 'org.projectlombok:lombok:1.16.16' - // annotationProcessor 'org.projectlombok:lombok:1.16.16' + annotationProcessor 'org.projectlombok:lombok:1.16.16' testCompile 'junit:junit:4.12' }