This commit is contained in:
Geek Wisdom 2021-10-19 16:49:45 +08:00 committed by GitHub
commit 57c317dc58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 133 additions and 1 deletions

60
src/dogequirks.cpp Normal file
View file

@ -0,0 +1,60 @@
// Copyright (c) 2021 The Dogecoin Core developers
// Portiosn Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Inspired from Original althorithm posted to voidware.com/moon_phase.htm.
// Details Original Althrithim below can be found on https://www.subsystems.us/free-resources.html
// PDF: https://www.subsystems.us/uploads/9/8/9/4/98948044/moonphase.pdf (Thanks @delbonis)
// PDF Mirror: https://geekwisdom.org/moonphase.pdf
#include <dogequirks.h>
#include<stdio.h>
int CDogeQuirks::moon_phase(int64_t nTime)
{
struct tm ts;
time_t time_val = nTime;
if (gmtime_r(&time_val, &ts) == nullptr) {
return -1; //timesync problem
}
return moon_phase(ts.tm_year+1900,ts.tm_mon+1,ts.tm_mday);
}
int CDogeQuirks::moon_phase(int year, int month, int day)
{
/*
calculates the moon phase. Returns a number between 0 and 7.
where:
0 = new moon.
4 = full moon.
Approximite cycle of each segment about 3 days. 0 and 8 are the same.
*/
const double DAYS_IN_YEAR = 365.25;
const double MOON_PERIOD= 29.53;
const double AVG_DAYS_IN_MONTH=30.6;
int num_days_year_part;
int num_days_month_part;
double total_days_elapsed;
double total_cycles_elapsed;
int total_cycles_elapsed_floor;
double total_cycles_remainder;
int final_cycle;
if (month < 3) {
year--;
month += 12;
}
month++;
num_days_year_part = year * DAYS_IN_YEAR;
num_days_month_part = month * AVG_DAYS_IN_MONTH;
total_days_elapsed = num_days_year_part +num_days_month_part +day-694039.09; /* subtract off at Fri Jan 09 1970 00:47:19 GMT+0000 */
total_cycles_elapsed = total_days_elapsed / MOON_PERIOD; //ie: (29.53 days) */
total_cycles_elapsed_floor = total_cycles_elapsed; /* cast to int to make floor */
total_cycles_remainder = total_cycles_elapsed - total_cycles_elapsed_floor;
final_cycle = total_cycles_remainder *8 + 0.5; /* count up to nearest int */
final_cycle = final_cycle & 7; /* 0 and 8 are the same so turn 8 into 0 */
return final_cycle;
}

20
src/dogequirks.h Normal file
View file

@ -0,0 +1,20 @@
// Copyright (c) 2021 The Dogecoin Core developers
// Portiosn Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
// Inspired from Original althorithm posted to voidware.com/moon_phase.htm.
// Copyright (c) 2021 The Dogecoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//This file is a little placeholder for 'quirks' that make Dogecoin
//stand out from other cyprtos
#include<stdio.h>
#include<util/time.h>
struct CDogeQuirks
{
static const unsigned int PROPOSED_TX_FEE = 0;
static const unsigned double PROPOSED_TX_PERCENT = 0.5;
static int moon_phase(int64_t);
static int moon_phase(int y, int m, int d);
};

View file

@ -0,0 +1,37 @@
#include "dogequirks.h"
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
BOOST_FIXTURE_TEST_SUITE(dogequirks_tests, BasicTestingSetup)
inline int date_test(const char *date)
{
int year;
int month;
int day;
sscanf(date, "%2d/%2d/%4d", &month,&day,&year);
int phase=CDogeQuirks::moon_phase(year,month,day);
return phase;
}
BOOST_AUTO_TEST_CASE(data_access_test)
{
//Test some "random" moon dates to see everything is working
//Date of creating this test case
BOOST_CHECK(date_test("5/23/2021") == 3); // not quite the full moon yet
BOOST_CHECK(date_test("5/25/2008") == 6); // #GeekPower
BOOST_CHECK(date_test("5/26/2021") == 4); // Actual full moon (and full lunar eclipse too!)
BOOST_CHECK(date_test("5/28/2021") == 5); // Just after the full moon
BOOST_CHECK(date_test("5/16/1976") == 5); // somebodys birthday maybe?
BOOST_CHECK(date_test("2/29/1980") == 4); // birth of an awesome leap year baby
BOOST_CHECK(date_test("6/22/2002") == 3); // wedding day
BOOST_CHECK(date_test("5/4/2011") == 1); // RD2D/C3PO
}
BOOST_AUTO_TEST_SUITE_END()

View file

@ -999,10 +999,12 @@ void CTxMemPool::UpdateParent(txiter entry, txiter parent, bool add)
CFeeRate CTxMemPool::GetMinFee(size_t sizelimit) const {
LOCK(cs);
if (!blockSinceLastRollingFeeBump || rollingMinimumFeeRate == 0)
return CFeeRate(llround(rollingMinimumFeeRate));
int64_t time = GetTime();
if (time > lastRollingFeeUpdate + 10) {
double halflife = ROLLING_FEE_HALFLIFE;
if (DynamicMemoryUsage() < sizelimit / 4)

View file

@ -34,6 +34,19 @@ extern RecursiveMutex cs_main;
/** Fake height value used in Coin to signify they are only in the memory pool (since 0.8) */
static const uint32_t MEMPOOL_HEIGHT = 0x7FFFFFFF;
inline double AllowFreeThreshold()
{
return COIN * 144 / 250;
}
inline bool AllowFree(double dPriority)
{
// Large (in bytes) low-priority (new, small-coin) transactions
// need a fee.
return dPriority > AllowFreeThreshold();
}
struct LockPoints
{
// Will be set to the blockchain height and median time past