Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReorgSafe - Test PR for address freezing for centrally managed tokens #83

Open
wants to merge 65 commits into
base: 0.2.99-Z-DevelopBaseline
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
033b11a
travis: move back to the minimal image
theuni Oct 18, 2017
74b9f9e
Merge #511: Travis CI: move back to the minimal image
dexX7 Dec 9, 2017
cacfd70
Add foundation 3 of 5 multisig to authorized senders
zathras-crypto Dec 10, 2017
b8ceef1
Add back in forced (manual) client upgrade
zathras-crypto Dec 10, 2017
d630b68
Add test for client expiry
zathras-crypto Dec 10, 2017
563d491
Add HashToAddress() helper to determine Bitcoin address from hash160 …
zathras-crypto Nov 28, 2017
fd3e69e
Add AddressToHash() helper to determine hash160 & version from Bitcoi…
zathras-crypto Nov 28, 2017
e57a9d6
Add type ints for new 'freeze', 'unfreeze' & 'change freeze setting' …
zathras-crypto Nov 28, 2017
6ee92bd
Add payload creation for 'change freeze setting' transaction
zathras-crypto Nov 28, 2017
05d2999
Add payload creation for 'freeze' transaction
zathras-crypto Nov 28, 2017
147000f
Add payload creation for 'unfreeze' transaction
zathras-crypto Nov 28, 2017
34ba058
Add sets to hold which properties allow freezing and which addresses …
zathras-crypto Nov 28, 2017
265608f
Add freezeAddress() & unfreezeAddress() helpers
zathras-crypto Nov 28, 2017
7567734
Add isAddressFrozen() check
zathras-crypto Nov 28, 2017
56ec86d
Add descriptions for new transactions
zathras-crypto Nov 28, 2017
0456097
Update consensus rules to allow freezing for managed properties
zathras-crypto Nov 28, 2017
651b3c2
Update consensus rules to enforce a waiting period for enabling freezing
zathras-crypto Nov 28, 2017
9c03cdc
Add enableFreezing() function
zathras-crypto Nov 28, 2017
7af2e6a
Add disableFreezing() function
zathras-crypto Nov 28, 2017
25d975f
Add isFreezingEnabled() helper
zathras-crypto Nov 28, 2017
92fe11d
Add processing for 'change freeze setting' transaction
zathras-crypto Nov 28, 2017
1e67c39
Add processing for 'freeze' transaction
zathras-crypto Nov 28, 2017
4d0e3ed
Add processing for 'unfreeze' transaction
zathras-crypto Nov 28, 2017
f2e1b42
Reject transactions from frozen addresses prior to logic processing
zathras-crypto Nov 28, 2017
ca91249
Add freeze error descriptions to errors.h
zathras-crypto Nov 28, 2017
8736b51
Load the freeze state at startup
zathras-crypto Nov 28, 2017
fc38b80
Add managedissuance attribute to omni_getproperty RPC response
zathras-crypto Nov 28, 2017
0247861
Add 'freezingenabled' attribute to omni_getproperty RPC response if p…
zathras-crypto Nov 28, 2017
338fa73
Add 'omni_changefreezesetting' RPC
zathras-crypto Nov 28, 2017
55ae04a
Add 'omni_sendfreeze' RPC
zathras-crypto Nov 28, 2017
3889c08
Add 'omni_sendunfreeze' RPC
zathras-crypto Nov 28, 2017
4540747
Commit bash script for freeze regtest scenario
zathras-crypto Nov 29, 2017
5f3ff4a
Increment DB_VERSION to force a reparse (consensus changes)
zathras-crypto Nov 29, 2017
f0255f1
Use DecodeBase58() in AddressToBytes() function - thanks @dexx7
zathras-crypto Nov 30, 2017
7436279
Add const to HashToAddress() to avoid copying object - thanks @dexx7
zathras-crypto Nov 30, 2017
243c930
Optimize isAddressFrozen() - thanks @dexx7
zathras-crypto Dec 1, 2017
aadafce
Return early from disableFreezing() if failure - thanks @dexx7
zathras-crypto Dec 1, 2017
75c7f1a
Move isAddressFrozen() check inside cs_tally LOCK - thanks @dexx7
zathras-crypto Dec 1, 2017
118e045
Move deletion of iterator in LoadFreezeState() - thanks @dexx7
zathras-crypto Dec 1, 2017
d0107fc
Add RequireManagedProperty() check to RPC tx creation - thanks @dexx7
zathras-crypto Dec 1, 2017
16d6cb9
Move lock after GetHeight() check in omni_getproperty RPC - thanks @d…
zathras-crypto Dec 1, 2017
2257e39
Add safety net to ensure update_tally_map() cannot take tokens from a…
zathras-crypto Dec 1, 2017
01c3436
Restrict Send All from trying to transfer frozen properties
zathras-crypto Dec 1, 2017
e8e657a
Add 'frozen' attribute to balance RPC responses if address is frozen …
zathras-crypto Dec 4, 2017
9874193
Swap 'Change Freeze Setting' for 'Enable Freezing' & 'Disable Freezin…
zathras-crypto Dec 5, 2017
fe1265c
Update testing scenario to use new explicit tx71 & tx72
zathras-crypto Dec 5, 2017
22cd4e0
Add freeze support to RPC payload creation
zathras-crypto Dec 5, 2017
d6f1a84
Make sure LoadFreeze() uses actual position in blockchain
zathras-crypto Dec 6, 2017
c02e63f
Bugfix: remove checksum from being included in the payload
zathras-crypto Dec 8, 2017
8f367c9
Clear the freeze state when `clear_all_state()` is called
zathras-crypto Dec 8, 2017
0328d4b
Add PrintFreezeState() function
zathras-crypto Dec 9, 2017
45ad203
Move wait period for freezing to tx.cpp
zathras-crypto Dec 9, 2017
d86b251
Update freeze regtests to include reorg tests
zathras-crypto Dec 9, 2017
82fe38e
Fix LoadFreezeState() failure due to not loading unfreeze txs
zathras-crypto Dec 9, 2017
1ba6f9a
Fix: only trigger assert on bad attempts to change BALANCE tally
zathras-crypto Dec 10, 2017
5dd7bce
Verify the Bitcoin address extracted from the payload is valid
zathras-crypto Dec 10, 2017
cda8ffe
Add freeze related payload unit tests
zathras-crypto Dec 10, 2017
531292e
Reparse if reorging the freeze state
zathras-crypto Dec 10, 2017
a6ce9aa
Update RPC-API documentation
zathras-crypto Dec 11, 2017
a6dd8a4
Force a reparse if a shutdown is forced
zathras-crypto Dec 11, 2017
cfd2adb
Add asserts to confirm freeze actions
zathras-crypto Dec 11, 2017
d3fa573
Merge #512: Reintroduce forced client upgrade
dexX7 Dec 11, 2017
2c43859
Add sanity check to LoadFreezeState()
zathras-crypto Dec 11, 2017
64150d9
Avoid merge conflict
zathras-crypto Dec 11, 2017
d8022fd
Merge branch 'develop' into 0.3-Z-FreezeReorgSafe
zathras-crypto Dec 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ addons:
hostname: bitcoin-tester

os: linux
language: generic
language: minimal
cache:
directories:
- depends/built
Expand Down
4 changes: 4 additions & 0 deletions src/omnicore/activation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "main.h"
#include "ui_interface.h"

#include <boost/filesystem.hpp>

#include <stdint.h>
#include <string>
#include <vector>
Expand Down Expand Up @@ -89,6 +91,8 @@ void CheckLiveActivations(int blockHeight)
PrintToLog(msgText);
PrintToConsole(msgText);
if (!GetBoolArg("-overrideforcedshutdown", false)) {
boost::filesystem::path persistPath = GetDataDir() / "MP_persist";
if (boost::filesystem::exists(persistPath)) boost::filesystem::remove_all(persistPath); // prevent the node being restarted without a reparse after forced shutdown
AbortNode(msgText, msgText);
}
}
Expand Down
73 changes: 73 additions & 0 deletions src/omnicore/createpayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "omnicore/createpayload.h"

#include "omnicore/convert.h"
#include "omnicore/utils.h"

#include "tinyformat.h"

Expand Down Expand Up @@ -316,6 +317,78 @@ std::vector<unsigned char> CreatePayload_ChangeIssuer(uint32_t propertyId)
return payload;
}

std::vector<unsigned char> CreatePayload_EnableFreezing(uint32_t propertyId)
{
std::vector<unsigned char> payload;
uint16_t messageType = 71;
uint16_t messageVer = 0;
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder32(propertyId);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyId);

return payload;
}

std::vector<unsigned char> CreatePayload_DisableFreezing(uint32_t propertyId)
{
std::vector<unsigned char> payload;
uint16_t messageType = 72;
uint16_t messageVer = 0;
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder32(propertyId);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyId);

return payload;
}

std::vector<unsigned char> CreatePayload_FreezeTokens(uint32_t propertyId, uint64_t amount, const std::string& address)
{
std::vector<unsigned char> payload;
uint16_t messageType = 185;
uint16_t messageVer = 0;
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder32(propertyId);
mastercore::swapByteOrder64(amount);
std::vector<unsigned char> addressBytes = AddressToBytes(address);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyId);
PUSH_BACK_BYTES(payload, amount);
payload.insert(payload.end(), addressBytes.begin(), addressBytes.end());

return payload;
}

std::vector<unsigned char> CreatePayload_UnfreezeTokens(uint32_t propertyId, uint64_t amount, const std::string& address)
{
std::vector<unsigned char> payload;
uint16_t messageType = 186;
uint16_t messageVer = 0;
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder32(propertyId);
mastercore::swapByteOrder64(amount);
std::vector<unsigned char> addressBytes = AddressToBytes(address);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyId);
PUSH_BACK_BYTES(payload, amount);
payload.insert(payload.end(), addressBytes.begin(), addressBytes.end());

return payload;
}

std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired)
{
std::vector<unsigned char> payload;
Expand Down
4 changes: 4 additions & 0 deletions src/omnicore/createpayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ std::vector<unsigned char> CreatePayload_CloseCrowdsale(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_Grant(uint32_t propertyId, uint64_t amount, std::string memo);
std::vector<unsigned char> CreatePayload_Revoke(uint32_t propertyId, uint64_t amount, std::string memo);
std::vector<unsigned char> CreatePayload_ChangeIssuer(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_EnableFreezing(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_DisableFreezing(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_FreezeTokens(uint32_t propertyId, uint64_t amount, const std::string& address);
std::vector<unsigned char> CreatePayload_UnfreezeTokens(uint32_t propertyId, uint64_t amount, const std::string& address);
std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired);
std::vector<unsigned char> CreatePayload_MetaDExCancelPrice(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired);
std::vector<unsigned char> CreatePayload_MetaDExCancelPair(uint32_t propertyIdForSale, uint32_t propertyIdDesired);
Expand Down
111 changes: 110 additions & 1 deletion src/omnicore/doc/rpc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,112 @@ $ omnicore-cli "omni_sendall" "3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY" "37FaKponF7zq

---

### omni_sendenablefreezing

Enables address freezing for a centrally managed property.

**Arguments:**

| Name | Type | Presence | Description |
|---------------------|---------|----------|----------------------------------------------------------------------------------------------|
| `fromaddress` | string | required | the address to send from (must be issuer of a managed property) |
| `propertyid` | number | required | the identifier of the tokens |

**Result:**
```js
"hash" // (string) the hex-encoded transaction hash
```

**Example:**

```bash
$ omnicore-cli "omni_sendenablefreezing" "3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY" 2
```

---

### omni_senddisablefreezing

Disables address freezing for a centrally managed property.

IMPORTANT NOTE: Disabling freezing for a property will UNFREEZE all frozen addresses for that property!

**Arguments:**

| Name | Type | Presence | Description |
|---------------------|---------|----------|----------------------------------------------------------------------------------------------|
| `fromaddress` | string | required | the address to send from (must be issuer of a managed property) |
| `propertyid` | number | required | the identifier of the tokens |

**Result:**
```js
"hash" // (string) the hex-encoded transaction hash
```

**Example:**

```bash
$ omnicore-cli "omni_senddisablefreezing" "3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY" 2
```

---

### omni_sendfreeze

Freeze an address for a centrally managed token.

Note: Only the issuer may freeze tokens, and only if the token is of the managed type with the freezing option enabled.

**Arguments:**

| Name | Type | Presence | Description |
|---------------------|---------|----------|----------------------------------------------------------------------------------------------|
| `fromaddress` | string | required | the address to send from (must be issuer of a managed property with freezing enabled |
| `toaddress` | string | required | the address to freeze |
| `propertyid` | number | required | the identifier of the tokens to freeze |
| `amount` | string | required | the amount to freeze (note: currently unused, frozen addresses cannot transact the property) |

**Result:**
```js
"hash" // (string) the hex-encoded transaction hash
```

**Example:**

```bash
$ omnicore-cli "omni_sendfreeze" "3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY" "3HTHRxu3aSDV4deakjC7VmsiUp7c6dfbvs" 2 1000
```

---

### omni_sendunfreeze

Unfreeze an address for a centrally managed token.

Note: Only the issuer may unfreeze tokens

**Arguments:**

| Name | Type | Presence | Description |
|---------------------|---------|----------|----------------------------------------------------------------------------------------------|
| `fromaddress` | string | required | the address to send from (must be issuer of a managed property with freezing enabled |
| `toaddress` | string | required | the address to unfreeze |
| `propertyid` | number | required | the identifier of the tokens to unfreeze |
| `amount` | string | required | the amount to unfreeze (note: currently unused |

**Result:**
```js
"hash" // (string) the hex-encoded transaction hash
```

**Example:**

```bash
$ omnicore-cli "omni_sendunfreeze" "3M9qvHKtgARhqcMtM5cRT9VaiDJ5PSfQGY" "3HTHRxu3aSDV4deakjC7VmsiUp7c6dfbvs" 2 1000
```

---

### omni_sendrawtx

Broadcasts a raw Omni Layer transaction.
Expand Down Expand Up @@ -560,7 +666,8 @@ Returns the token balance for a given address and property.
```js
{
"balance" : "n.nnnnnnnn", // (string) the available balance of the address
"reserved" : "n.nnnnnnnn" // (string) the amount reserved by sell offers and accepts
"reserved" : "n.nnnnnnnn", // (string) the amount reserved by sell offers and accepts
"frozen" : "n.nnnnnnnn" // (string) the amount frozen by the issuer (applies to managed properties only)
}
```

Expand Down Expand Up @@ -878,6 +985,8 @@ Returns details for about the tokens or smart property to lookup.
"issuer" : "address", // (string) the Bitcoin address of the issuer on record
"creationtxid" : "hash", // (string) the hex-encoded creation transaction hash
"fixedissuance" : true|false, // (boolean) whether the token supply is fixed
"managedissuance" : true|false, // (boolean) whether the token supply is managed by the issuer
"freezingenabled" : true|false, // (boolean) whether freezing is enabled for the property (managed properties only)
"totaltokens" : "n.nnnnnnnn" // (string) the total number of tokens in existence
}
```
Expand Down
15 changes: 15 additions & 0 deletions src/omnicore/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ inline std::string error_str(int ec) {
case PKT_ERROR -2:
ec_str = "Failed to interpret transaction";
break;
case PKT_ERROR -3:
ec_str = "Sender is frozen for the property";
break;
case PKT_ERROR -22:
ec_str = "Transaction type or version not permitted";
break;
Expand Down Expand Up @@ -321,6 +324,18 @@ inline std::string error_str(int ec) {
case PKT_ERROR_TOKENS -46:
ec_str = "Receiver has an active crowdsale";
break;
case PKT_ERROR_TOKENS -47:
ec_str = "Freezing is not enabled for the property";
break;
case PKT_ERROR_TOKENS -48:
ec_str = "Address is not frozen";
break;
case PKT_ERROR_TOKENS -49:
ec_str = "Freezing is already enabled for the property";
break;
case PKT_ERROR_TOKENS -50:
ec_str = "Address is already frozen";
break;

default:
ec_str = "Unknown error";
Expand Down
6 changes: 5 additions & 1 deletion src/omnicore/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ void COmniFeeCache::AddFee(const uint32_t &propertyId, int block, const int64_t
// overflow - there is no way the fee cache should exceed the maximum possible number of tokens, not safe to continue
const std::string& msg = strprintf("Shutting down due to fee cache overflow (block %d property %d current %d amount %d)\n", block, propertyId, currentCachedAmount, amount);
PrintToLog(msg);
if (!GetBoolArg("-overrideforcedshutdown", false)) AbortNode(msg, msg);
if (!GetBoolArg("-overrideforcedshutdown", false)) {
boost::filesystem::path persistPath = GetDataDir() / "MP_persist";
if (boost::filesystem::exists(persistPath)) boost::filesystem::remove_all(persistPath); // prevent the node being restarted without a reparse after forced shutdown
AbortNode(msg, msg);
}
}
int64_t newCachedAmount = currentCachedAmount + amount;

Expand Down
1 change: 1 addition & 0 deletions src/omnicore/notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ bool CheckAlertAuthorization(const std::string& sender)
whitelisted.insert("16oDZYCspsczfgKXVj3xyvsxH21NpEj94F"); // Adam <[email protected]>
whitelisted.insert("1883ZMsRJfzKNozUBJBTCxQ7EaiNioNDWz"); // Zathras <[email protected]>
whitelisted.insert("1HHv91gRxqBzQ3gydMob3LU8hqXcWoLfvd"); // dexX7 <[email protected]>
whitelisted.insert("34kwkVRSvFVEoUwcQSgpQ4ZUasuZ54DJLD"); // multisig (signatories are Craig, Adam, Zathras, dexX7, JR)

// Testnet / Regtest
// use -omnialertallowsender for testing
Expand Down
Loading