Skip to content

Commit

Permalink
v1.0.3 patch
Browse files Browse the repository at this point in the history
Patch v1.0.3 for lite wallet. Version bumped. Latest coin source updated.
  • Loading branch information
Vordas committed Jul 24, 2018
1 parent d943fe6 commit c169d16
Show file tree
Hide file tree
Showing 13 changed files with 268 additions and 66 deletions.
11 changes: 3 additions & 8 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Worktips lite wallet v1.0.2.3
# Worktips lite wallet v1.0.3

## Change log for v1.0.2.3 release
## Change log for v1.0.3 release

- connection bug fixes
- better remote node connection handling
- minor menu updates
- minor GUI updates
- various fixes and code cleanups
- wallet now loads even if remote node is down
- updated source
2 changes: 1 addition & 1 deletion cryptonote/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are
set(CMAKE_SKIP_INSTALL_RULES OFF)
set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY ON)
set(CMAKE_SUPPRESS_REGENERATION ON)
set(DO_TESTS ON CACHE STRING "Spend time making tests? Defaults to ON")
set(DO_TESTS OFF CACHE STRING "Spend time making tests? Defaults to ON")
set(STATIC ON CACHE BOOL "Link libraries statically")

set(ENABLE_AVX OFF CACHE STRING "Enable RocksDB AVX/AVX2 support detection? Defaults to OFF")
Expand Down
28 changes: 28 additions & 0 deletions cryptonote/Changelogs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
This Fork contains :

1.Block reward reduction (i.e The currect block reward will be divided by 3). Emmission factor is changed to 20.


2.Difficulty Target has been changed to 90 sseconds. For faster block transactions.

3.Difficulty Algorithm has beeb changed to LWMA-V2. Thanks to Zawy. Thanks to TRTL devs for their small tweaks.

4.Timestamp attacks are now ineffective. Thanks to Jagerman.

5.Difficulty Algorithm is now more sensitive in 50x attacks. Thanks to fireice.

6.Building TEST is disabled.

This commit contains all the changes in one place. If you want to see the above changes in individual commits, refer https://github.com/samvicky26/worktipscoin1/tree/dev3



About the Block reward reduction:

At the time of writing this the block reward was 496992.2409 WTIP.The block reward will be calculated using this formula(https://github.com/samvicky26/worktipscoin1/blob/dc8d17bc8356d609e503ffbfaeda2155f6ef1a3f/src/CryptoNoteCore/Currency.cpp#L179).
That will be baseReward = (Total Supply - Mined Coins)/ 2^(emmision factor).
After the fork , the reward will be calculated by using 20 as emmision factor && 22 as emmision smoothing factor.A smoothing factor has been added to stop the drastic base reward drop.
The smoothing factor calculates the final base reward using this formula .
Final Base reward =((Total Supply - Mined Coins)/ 2^(emmision factor))+((Total Supply - Mined Coins)/ 2^(emmision smoothing factor)).

After doing the math, the base reward will be 155299.4409651349.
4 changes: 2 additions & 2 deletions cryptonote/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This is the reference code for [Worktips](https://worktips.info) cryptocurrency.
This is the reference code for [Worktips](https://worktips.info) cryptocurrency. Read the Changlogs.txt for more info about the current fork.

## Worktips is based on the [TurtleCoin](https://github.com/turtlecoin) v0.5.0 code base, and this repository is a re-upload of the latest Worktips source code with updated and corrected licences, credits and copyrights.
### Worktips is based on the [TurtleCoin](https://github.com/turtlecoin) v0.5.0 code base.

* Official homepage: [Worktips](http://worktips.info)
* Official repository: [Worktips GitHub](https://github.com/worktips/worktipscoin)
Expand Down
35 changes: 25 additions & 10 deletions cryptonote/src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2014-2018, The Monero Project
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018, Worktips Developers
//
// Please see the included LICENSE file for more information.

Expand All @@ -13,21 +14,34 @@

namespace CryptoNote {
namespace parameters {

const uint64_t DIFFICULTY_TARGET = 120; // seconds
const uint64_t DIFFICULTY_TARGET_V2 = 90; // seconds

const uint32_t CRYPTONOTE_MAX_BLOCK_NUMBER = 500000000;
const size_t CRYPTONOTE_MAX_BLOCK_BLOB_SIZE = 500000000;
const size_t CRYPTONOTE_MAX_TX_SIZE = 1000000000;
const uint64_t CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 0x1db32;
const uint32_t CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW = 10;
const uint64_t CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT = 60 * 60 * 2;
const uint64_t CRYPTONOTE_BLOCK_FUTURE_TIME_LIMIT_V3 = 3 * DIFFICULTY_TARGET;

const size_t BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW = 60;
const size_t BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V3 = 11;

const uint64_t MONEY_SUPPLY = UINT64_C(18446744073709551615);
const uint32_t ZAWY_DIFFICULTY_BLOCK_INDEX = 10500;
const size_t ZAWY_DIFFICULTY_V2 = 0;
const uint8_t ZAWY_DIFFICULTY_DIFFICULTY_BLOCK_VERSION = 0;

const uint64_t LWMA_2_DIFFICULTY_BLOCK_INDEX = 96000;

const uint64_t DIFFICULTY_WINDOW_V3 = 60;
const uint64_t DIFFICULTY_BLOCKS_COUNT_V3 = DIFFICULTY_WINDOW_V3 + 1;

const unsigned EMISSION_SPEED_FACTOR = 18;
const unsigned EMISSION_SPEED_FACTOR_V2 = 20;
const unsigned EMISSION_SMOOTHING_FACTOR_V2 = 22;
const uint64_t GENESIS_BLOCK_REWARD = UINT64_C(0);
static_assert(EMISSION_SPEED_FACTOR <= 8 * sizeof(uint64_t), "Bad EMISSION_SPEED_FACTOR");

Expand All @@ -46,7 +60,6 @@ const uint16_t MAXIMUM_MIXIN_V1 = 30;
const uint32_t MIXIN_LIMITS_V1_HEIGHT = 44500;
const uint64_t DEFAULT_DUST_THRESHOLD = UINT64_C(100000);

const uint64_t DIFFICULTY_TARGET = 120; // seconds
const uint64_t EXPECTED_NUMBER_OF_BLOCKS_PER_DAY = 24 * 60 * 60 / DIFFICULTY_TARGET;
const size_t DIFFICULTY_WINDOW = 17;
const size_t DIFFICULTY_WINDOW_V1 = 720;
Expand Down Expand Up @@ -78,6 +91,7 @@ const uint32_t KEY_IMAGE_CHECKING_BLOCK_INDEX = 0;
const uint32_t UPGRADE_HEIGHT_V2 = 10500;
const uint32_t UPGRADE_HEIGHT_V3 = 27500;
const uint32_t UPGRADE_HEIGHT_V4 = 28000; // Upgrade height for CN-Lite Variant 1 switch.
const uint32_t UPGRADE_HEIGHT_V5 = 96000;
const unsigned UPGRADE_VOTING_THRESHOLD = 90; // percent
const uint32_t UPGRADE_VOTING_WINDOW = EXPECTED_NUMBER_OF_BLOCKS_PER_DAY; // blocks
const uint32_t UPGRADE_WINDOW = EXPECTED_NUMBER_OF_BLOCKS_PER_DAY; // blocks
Expand All @@ -100,6 +114,7 @@ const uint8_t BLOCK_MAJOR_VERSION_1 = 1;
const uint8_t BLOCK_MAJOR_VERSION_2 = 2;
const uint8_t BLOCK_MAJOR_VERSION_3 = 3;
const uint8_t BLOCK_MAJOR_VERSION_4 = 4;
const uint8_t BLOCK_MAJOR_VERSION_5 = 5;
const uint8_t BLOCK_MINOR_VERSION_0 = 0;
const uint8_t BLOCK_MINOR_VERSION_1 = 1;

Expand All @@ -126,17 +141,17 @@ const size_t P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT = 5000; //
const char P2P_STAT_TRUSTED_PUB_KEY[] = "8f80f9a5a434a9f1510d13336228debfee9c918ce505efe225d8c94d045fa115";

const char* const SEED_NODES[] = {
"45.32.237.184:17239",
"45.63.91.13:17239",
"45.32.171.185:17239",
"108.61.86.119:17239"
"45.32.237.184:17239",
"45.32.42.166:17239",
"45.32.171.185:17239",
"108.61.86.119:17239"
};

struct CheckpointData {
uint32_t index;
const char* blockId;
};
struct CheckpointData {
uint32_t index;
const char* blockId;
};
const std::initializer_list<CheckpointData> CHECKPOINTS = { };

} // CryptoNote
24 changes: 7 additions & 17 deletions cryptonote/src/CryptoNoteCore/BlockchainCache.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
// Copyright (c) 2012-2017, The CryptoNote developers, The Bytecoin developers
// Copyright (c) 2014-2018, The Monero Project
// Copyright (c) 2018, The TurtleCoin Developers
// Copyright (c) 2018, The Worktips Developers
//
// This file is part of Bytecoin.
//
// Bytecoin is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Bytecoin 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
// Please see the included LICENSE file for more information.

#include "BlockchainCache.h"

Expand Down Expand Up @@ -952,10 +942,10 @@ Difficulty BlockchainCache::getDifficultyForNextBlock() const {
Difficulty BlockchainCache::getDifficultyForNextBlock(uint32_t blockIndex) const {
assert(blockIndex <= getTopBlockIndex());
uint8_t nextBlockMajorVersion = getBlockMajorVersionForHeight(blockIndex+1);
auto timestamps = getLastTimestamps(currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion), blockIndex, skipGenesisBlock);
auto timestamps = getLastTimestamps(currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion, blockIndex), blockIndex, skipGenesisBlock);
auto commulativeDifficulties =
getLastCumulativeDifficulties(currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion), blockIndex, skipGenesisBlock);
return currency.nextDifficulty(nextBlockMajorVersion, blockIndex, std::move(timestamps), std::move(commulativeDifficulties));
getLastCumulativeDifficulties(currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion, blockIndex), blockIndex, skipGenesisBlock);
return currency.getNextDifficulty(nextBlockMajorVersion, blockIndex, std::move(timestamps), std::move(commulativeDifficulties));
}

Difficulty BlockchainCache::getCurrentCumulativeDifficulty() const {
Expand Down
59 changes: 56 additions & 3 deletions cryptonote/src/CryptoNoteCore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Core::Core(const Currency& currency, Logging::ILogger& logger, Checkpoints&& che
upgradeManager->addMajorBlockVersion(BLOCK_MAJOR_VERSION_2, currency.upgradeHeight(BLOCK_MAJOR_VERSION_2));
upgradeManager->addMajorBlockVersion(BLOCK_MAJOR_VERSION_3, currency.upgradeHeight(BLOCK_MAJOR_VERSION_3));
upgradeManager->addMajorBlockVersion(BLOCK_MAJOR_VERSION_4, currency.upgradeHeight(BLOCK_MAJOR_VERSION_4));
upgradeManager->addMajorBlockVersion(BLOCK_MAJOR_VERSION_5, currency.upgradeHeight(BLOCK_MAJOR_VERSION_5));

transactionPool = std::unique_ptr<ITransactionPoolCleanWrapper>(new TransactionPoolCleanWrapper(
std::unique_ptr<ITransactionPool>(new TransactionPool(logger)),
Expand Down Expand Up @@ -519,12 +520,12 @@ Difficulty Core::getDifficultyForNextBlock() const {

uint8_t nextBlockMajorVersion = getBlockMajorVersionForHeight(topBlockIndex);

size_t blocksCount = std::min(static_cast<size_t>(topBlockIndex), currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion));
size_t blocksCount = std::min(static_cast<size_t>(topBlockIndex), currency.difficultyBlocksCountByBlockVersion(nextBlockMajorVersion, topBlockIndex));

auto timestamps = mainChain->getLastTimestamps(blocksCount);
auto difficulties = mainChain->getLastCumulativeDifficulties(blocksCount);

return currency.nextDifficulty(nextBlockMajorVersion, topBlockIndex, timestamps, difficulties);
return currency.getNextDifficulty(nextBlockMajorVersion, topBlockIndex, timestamps, difficulties);
}

std::vector<Crypto::Hash> Core::findBlockchainSupplement(const std::vector<Crypto::Hash>& remoteBlockIds,
Expand Down Expand Up @@ -1128,6 +1129,58 @@ bool Core::getBlockTemplate(BlockTemplate& b, const AccountPublicAddress& adr, c
b.previousBlockHash = getTopBlockHash();
b.timestamp = time(nullptr);



/* Ok, so if an attacker is fiddling around with timestamps on the network,
they can make it so all the valid pools / miners don't produce valid
blocks. This is because the timestamp is created as the users current time,
however, if the attacker is a large % of the hashrate, they can slowly
increase the timestamp into the future, shifting the median timestamp
forwards. At some point, this will mean the valid pools will submit a
block with their valid timestamps, and it will be rejected for being
behind the median timestamp / too far in the past. The simple way to
handle this is just to check if our timestamp is going to be invalid, and
set it to the median.
Once the attack ends, the median timestamp will remain how it is, until
the time on the clock goes forwards, and we can start submitting valid
timestamps again, and then we are back to normal. */

/* Thanks to jagerman for this patch:
https://github.com/loki-project/loki/pull/26 */

/* How many blocks we look in the past to calculate the median timestamp */
uint64_t blockchain_timestamp_check_window;

if (height >= CryptoNote::parameters::LWMA_2_DIFFICULTY_BLOCK_INDEX)
{
blockchain_timestamp_check_window = CryptoNote::parameters::BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW_V3;
}
else
{
blockchain_timestamp_check_window = CryptoNote::parameters::BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW;
}

/* Skip the first N blocks, we don't have enough blocks to calculate a
proper median yet */
if (height >= blockchain_timestamp_check_window)
{
std::vector<uint64_t> timestamps;

/* For the last N blocks, get their timestamps */
for (size_t offset = height - blockchain_timestamp_check_window; offset < height; offset++)
{
timestamps.push_back(getBlockTimestampByIndex(offset));
}

uint64_t medianTimestamp = Common::medianValue(timestamps);

if (b.timestamp < medianTimestamp)
{
b.timestamp = medianTimestamp;
}
}

size_t medianSize = calculateCumulativeBlocksizeLimit(height) / 2;

assert(!chainsStorage.empty());
Expand Down Expand Up @@ -1471,7 +1524,7 @@ std::error_code Core::validateBlock(const CachedBlock& cachedBlock, IBlockchainC
}
}

if (block.timestamp > getAdjustedTime() + currency.blockFutureTimeLimit()) {
if (block.timestamp > getAdjustedTime() + currency.blockFutureTimeLimit(previousBlockIndex+1)) {
return error::BlockValidationError::TIMESTAMP_TOO_FAR_IN_FUTURE;
}

Expand Down
2 changes: 1 addition & 1 deletion cryptonote/src/CryptoNoteCore/CryptoNoteSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void serialize(ParentBlockSerializer& pbs, ISerializer& serializer) {

void serializeBlockHeader(BlockHeader& header, ISerializer& serializer) {
serializer(header.majorVersion, "major_version");
if (header.majorVersion > BLOCK_MAJOR_VERSION_4) {
if (header.majorVersion > BLOCK_MAJOR_VERSION_5) {
throw std::runtime_error("Wrong major version");
}

Expand Down
Loading

0 comments on commit c169d16

Please sign in to comment.