Commit Graph

682 Commits

Author SHA1 Message Date
catbref
ef790a8cb1 Fix missing groupId 0 entry in output from API call GET /chat/active/{address} 2020-05-13 16:30:28 +01:00
catbref
cea0cee9a8 Names: fixes to allow name change and tests to cover 2020-05-13 15:07:36 +01:00
catbref
d9f784ed2b Registered names: changing 'owner' and allowing renaming.
REGISTER_NAME has an "owner" field which can be different from the actual
registrant (transaction creator's public key, used for signing transaction).

This allowed people to register names to be owned by someone else, thus breaking
the whole "one name per account" aspect.

So now "owner" is removed from REGISTER_NAME, and the actual owner address is
derived from transaction creator's public key, as you would expect.

Similarly, UPDATE_NAME has a corresponding "newOwner" field which has been removed.

In addition, UPDATE_NAME now allows users to change their registered name using a new
"newName" field.

Various changes made to DB, Name class, etc. to accomodate above, along with some minor
bug-fixes and comment improvements/corrections.

Needs new unit tests to cover both new functionality and old!
2020-05-13 10:19:56 +01:00
catbref
f29ae656b9 More work on CHAT
Always add group 0 info to output of API call GET /chats/active/{address}.
No groupName entry as it's "no group" or "group-less" or "not group related".
Timestamp also might be omitted if no message found.

Fix output of POST /chats/compute so it doesn't include zeroed 64-byte signature.
2020-05-12 20:27:09 +01:00
catbref
a9852e5305 More work on CHAT API / support.
Renamed GET /chats/search to /chats/messages.

Added GET /chats/active/{address} to return lists of group chats
and direct chats involving {address}, where a chat message exists.
2020-05-12 14:28:41 +01:00
catbref
32470fa641 Improve CHAT API and repository support.
Change CHAT API call GET /chat/search to better support the two
main scenarios of:

group-based chatting: supply txGroupId only
private chatting: supply 2 'involving' addresses only

Added some DB indexes to cater for above.

GET /chat/search now returns specialized ChatMessage objects
instead of ChatTransactions. This is to reduce unnecessary fetching
of data from repository, and onward sending to API client.
2020-05-12 10:02:41 +01:00
catbref
0d1c08bf96 Add index on DB Names.owner to help find names by owner 2020-05-12 10:02:26 +01:00
catbref
026c904ce4 Change processing of network TRANSACTION_SIGNATURES message.
Previously Controller would loop through the transaction signatures,
discard those already known, and then requesting the full transaction
via peer.getResponse(). This would tie up a networking thread for some
time and also potentially cause repository deadlocks, although the latter
could have been fixed another way.

However, the code after peer.getResponse() was identical to the code
processing an incoming TRANSACTION message. Now instead of requesting
and waiting for then processing each transaction, Controller simply
sends the peer a GET_TRANSACTION for each unknown transaction signature.

As the peer responds with corresponding TRANSACTION messages, these can
be processed individually with shorter period of locking.
2020-05-12 08:03:11 +01:00
catbref
59ae070c83 Fix API call POST /peers so it returns "false" for existing peer, instead of throwing / Internal Server Error 2020-05-11 12:59:56 +01:00
catbref
2ab695f308 NTP: don't call shutdownNow() on null instanceExecutor
When using fixed NTP offset, e.g. via "testNtpoffset" in settings.json,
Controller calls NTP.shutdownNow() which throws a NPE because
NTP.instanceExecutor is null.
2020-05-11 12:59:45 +01:00
catbref
f0ff77cd31 Fix ChatTransaction w.r.t. txGroupId meaning. Relax no-QORT PoW difficulty. 2020-05-11 12:58:46 +01:00
catbref
e241d9fa67 Split CHAT compute into separate API call to help UI 2020-05-11 12:58:05 +01:00
catbref
5e9b0cd03c Fix GroupInvites.expires_when in DB to re-allow NULL 2020-05-11 12:55:58 +01:00
catbref
a5c437913f Transaction.isValidTxGroupId() changed from private to protected - needed so ChatTransaction can override 2020-05-11 12:55:22 +01:00
catbref
3fa7da5115 Fix for incorrect blocksMinted count. Added test to cover 2020-05-08 08:51:56 +01:00
catbref
6d8f41ab05 Fix long overflow in Block.distributeBlockRewardToQoraHolders()
Sadly no native 128bit integer support in Java 11 so resorting to using
BigInteger.

Added/improved unit tests to cover.
2020-05-07 16:37:40 +01:00
catbref
c7c419a3cd Bump version in pom.xml to v1.1.0 ready for launch 2020-05-07 13:30:34 +01:00
catbref
3094ec3c26 Massive clean-up of DB & conversion to long for timestamps
Collated all development changes to DB so now we build
initial DB structure directly with final layout.
i.e. no ALTER TABLE, etc.

Reordered HSQLDB 'CREATE TYPE' statements into alphabetical order
for easier maintainability.

Replaced TIMESTAMP WITH TIME ZONE with simple BIGINT ("EpochMillis").
Timezone conversion is now a presentation task, rather than having
pretty values in database.

Removed associated conversion methods, like toOffsetDateTime(),
fromOffsetDateTime() and getZonedTimestampMilli().

Renamed some DB columns to make them more obviously timestamps, like:
Names.registered is now Names.registered_when.

Removed IFNULL(balance, 0) from HSQLDBAccountRepository as balances
are never null, or actually never 0 either.

Added more tests to increase API call, and hence repository, coverage.

Removed unused "milestone block" from Transactions.
2020-05-07 12:16:22 +01:00
catbref
359a35931e Fix broken Transaction.getUnconfirmedTransactions() and getInvalidTransactions() 2020-05-07 12:15:09 +01:00
catbref
9e0001c4f6 Improved comments, variable names, etc. for some repository interfaces 2020-05-07 10:22:44 +01:00
catbref
53112709fe Improve comment & tidy annotation in GroupData 2020-05-07 10:11:35 +01:00
catbref
d1bc500ab9 Correct two unit tests from BigDecimal to long/int. 2020-05-06 15:03:41 +01:00
catbref
74b5401e84 Merge chain-stall, blocksMinted and other fixes 2020-05-06 08:01:51 +01:00
catbref
d2559f36ce Fix for Block not correctly adjusting accounts' blocksMinted values.
Added BlocksMintedCountTests to cover above.
2020-05-05 16:10:54 +01:00
catbref
0cc9cd728e Fix for chain-stall relating to freshly cancelled reward-shares.
In some cases, a freshly cancelled reward-share could still have
an associated signed timestamp. Block.mint() failed to spot this
and used an incorrect "online account" index when building the
to-be-minted block.

Block.mint() now checks that AccountRepository.getRewardShareIndex()
doesn't return null, i.e. indicating that the associated reward-share
for that "online account" no longer exists.

In turn, AccountRepository.getRewardShareIndex() didn't fulfill its
contract of returning null when the passed public key wasn't present
in the repository. So this method has been corrected also.

AccountRepository.rewardShareExists(byte[] publicKey) : boolean added.

BlockMinter had another bug where it didn't check the return from
Block.remint() for null properly. This has been fixed.

BlockMinter now has additional logging, with cool-off to prevent log
spam, for situations where minting could not happen.

Unit test (DisagreementTests) added to cover cancelled reward-share
case above. BlockMinter testing support slightly modified to help.
2020-05-05 11:09:46 +01:00
catbref
e5cf76f3e0 Replace throwing IllegalStateException with more defensive log & null in Block/BlockMinter 2020-05-04 15:50:10 +01:00
catbref
44e8b3e6e7 Log when BlockMinter fails to acquire blockchain lock after waiting 2020-05-04 14:33:10 +01:00
catbref
1bca152d9c Reduce minBlockchainPeers for now 2020-05-04 14:32:42 +01:00
catbref
4edc3ee121 Fix AT transaction reference lookup/generation in light of new last-ref scheme 2020-05-04 09:32:18 +01:00
catbref
e9f29767c8 Change Transaction.countUnconfirmedByCreator() to disregard CHAT transactions.
This is because CHAT transactions have intrinsic anti-spam/DoS prevention
by requiring proof of work.
2020-05-04 09:29:07 +01:00
catbref
e2916b130b No need to store repository handle in Block$ExpandedAccount 2020-05-04 09:19:17 +01:00
catbref
538e117abd Clean up Transaction.isStillValidUnconfirmed()
Brought more into line with isValidUnconfirmed().
No need to update creator's lastReference under new last-ref scheme.

Correspondingly, no need to acquire blockchain lock or repository
shenanigans in getUnconfirmedTransactions() and getInvalidTransactions()
for the same reason.

getInvalidTransactions() seems to be unused and may well be cleaned up
in a future commit.
2020-05-04 09:14:52 +01:00
catbref
71e80bd02f Convert to Account.modifyAssetBalance()
Change code of the form (assetId aspect not shown):

account.setConfirmedBalance( account.getConfirmedBalance(), amount )

to:

account.modifyAssetBalance( amount )

Also tidied "0 - value" to use unary negate: "- value"
2020-05-04 08:45:31 +01:00
catbref
800103225b Remove pointless "return" in DeployAtTransaction 2020-05-04 08:18:59 +01:00
catbref
cfb7a3cc4c Minor terminology correction in GenesisBlock 2020-05-04 08:18:33 +01:00
catbref
3185cf23df Replace throwing IllegalStateException with more defensive log & null in Block/BlockMinter 2020-05-04 08:18:15 +01:00
catbref
3ac1b36549 Restrict API call POST /chat to prevent CPU abuse 2020-05-04 08:17:05 +01:00
catbref
55e99062ca CHAT PoW difficulty now much greater if sender has no QORT balance 2020-05-01 11:01:52 +01:00
catbref
edb56b74da Merge branch 'chat' into launch 2020-05-01 10:51:38 +01:00
catbref
233ace23de AT transactions now either have null message or null amount&assetId.
AT transaction transformer changed to refuse to deserialize AT transactions,
as they should never appear on the wire.

Ditto for GENESIS transactions.
2020-05-01 10:42:32 +01:00
catbref
e1f3b9a7a3 Update QortalATAPI.putTransactionAfterTimestampIntoA() to use Transaction.getRecipientAddresses 2020-05-01 10:20:25 +01:00
catbref
6be88ac86e In BTCACCT, use Account to fetch balance instead of direct from DB 2020-05-01 10:19:28 +01:00
catbref
d03cca2e76 Merge branch 'BTC-ACCT' into launch 2020-05-01 10:09:54 +01:00
catbref
e86143426b Fix potentially overflowing multiply in Block reward processing.
Change BlockChain config to use AmountTypeAdapter instead of
creating duplicated long versions of BigDecimal values.

Some tidying to Amounts class.
2020-05-01 08:57:15 +01:00
catbref
a309f8de9e Fix dead code warning in Account 2020-05-01 08:56:49 +01:00
catbref
df15f81b9f Fix whitespace 2020-05-01 08:56:27 +01:00
catbref
6ab50e4dff Fix some SonarLint complaints 2020-05-01 08:56:03 +01:00
catbref
476d9e4c95 Converted tests from BigDecimal to long
Moved Asset.MULTIPLIER, etc. to Amounts class.

Had to reintroduce BigInteger for asset trading code.
Various helper methods added to Amounts class.

Payment.process/orphan no longer needs unused transaction
signature or reference.

Added post block process/orphan tidying, which currently deletes zero account balances to satisfy post-orphan checks in unit tests.

Fix for possible bug when orphaning TRANSFER_PRIVS.

Added RewardSharePercentTypeAdapter like AmountTypeAdapter.

Replaced a whole load of JAXB-special getters with type-adapters.

Tests looking good!
2020-05-01 08:41:35 +01:00
catbref
9eaf31707a Massive conversion from BigDecimal to long.
Now possible thanks to removing Qora v1 support.

Maximum asset quantities now unified to 10_000_000_000,
to 8 decimal places, removing prior 10 billion billion
indivisible maximum.

All values can now fit into a 64bit long.
(Except maybe when processing asset trades).

Added a general-use JAXB AmountTypeAdapter for converting
amounts to/from String/long.

Asset trading engine split into more methods for easier
readability.

Switched to using FIXED founder block reward distribution code,
ready for launch.

In HSQLDBDatabaseUpdates,
QortalAmount changed from DECIMAL(27, 0) to BIGINT
RewardSharePercent added to replace DECIMAL(5,2) with INT

Ripped out unused Transaction.isInvolved and Transaction.getAmount
in all subclasses.

Changed
  Transaction.getRecipientAccounts() : List<Account>
to
  Transaction.getRecipientAddresses() : List<String>
as only addresses are ever used.

Corrected returned values for above getRecipientAddresses() for
some transaction subclasses.

Added some account caching to some transactions to reduce repeated
loads during validation and then processing.

Transaction transformers:

Changed serialization of asset amounts from using 12 bytes to
now standard 8 byte long.

Updated transaction 'layouts' to reflect new sizes.

RewardShareTransactionTransformer still uses 8byte long to represent
reward share percent.

Updated some unit tests - more work needed!
2020-05-01 08:40:32 +01:00
catbref
e0007269b9 Initial attempt at transient CHAT transaction type.
CHAT transactions don't ever get included into a block.
They use a memory-intensive proof-of-work instead of a fee.
Reference field isn't checked but must be present.
Recipient is optional.
isText/isEncrypted as per MESSAGE, basically indicative flags only.

Some API support.

Memory PoW takes roughly 800ms on Ryzen 3600, maybe 2400ms on QORTector?
2020-04-28 16:45:09 +01:00