Skip to content

Commit

Permalink
Add New Bucket for Specific Amount Range (#4661)
Browse files Browse the repository at this point in the history
* Add additional bucket for amounts between  Ӿ0.000001 and Ӿ0.0003

include Ӿ0.000001 into new bucket

* Adjust testcases to account for the additional bucket

---------

Co-authored-by: gr0vity <gr0vity.dev@gmail.com>
  • Loading branch information
gr0vity-dev and gr0vity authored Jul 9, 2024
1 parent 47b18f9 commit 59f6b31
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
10 changes: 5 additions & 5 deletions nano/core_test/scheduler_buckets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,23 @@ TEST (buckets, construction)
nano::scheduler::buckets buckets;
ASSERT_EQ (0, buckets.size ());
ASSERT_TRUE (buckets.empty ());
ASSERT_EQ (62, buckets.bucket_count ());
ASSERT_EQ (63, buckets.bucket_count ());
}

TEST (buckets, insert_Gxrb)
{
nano::scheduler::buckets buckets;
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
ASSERT_EQ (1, buckets.bucket_size (48));
ASSERT_EQ (1, buckets.bucket_size (49));
}

TEST (buckets, insert_Mxrb)
{
nano::scheduler::buckets buckets;
buckets.push (1000, block1 (), nano::Mxrb_ratio);
ASSERT_EQ (1, buckets.size ());
ASSERT_EQ (1, buckets.bucket_size (13));
ASSERT_EQ (1, buckets.bucket_size (14));
}

// Test two blocks with the same priority
Expand All @@ -138,7 +138,7 @@ TEST (buckets, insert_same_priority)
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1000, block2 (), nano::Gxrb_ratio);
ASSERT_EQ (2, buckets.size ());
ASSERT_EQ (2, buckets.bucket_size (48));
ASSERT_EQ (2, buckets.bucket_size (49));
}

// Test the same block inserted multiple times
Expand All @@ -148,7 +148,7 @@ TEST (buckets, insert_duplicate)
buckets.push (1000, block0 (), nano::Gxrb_ratio);
buckets.push (1000, block0 (), nano::Gxrb_ratio);
ASSERT_EQ (1, buckets.size ());
ASSERT_EQ (1, buckets.bucket_size (48));
ASSERT_EQ (1, buckets.bucket_size (49));
}

TEST (buckets, insert_older)
Expand Down
5 changes: 3 additions & 2 deletions nano/node/scheduler/buckets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void nano::scheduler::buckets::seek ()

void nano::scheduler::buckets::setup_buckets (uint64_t maximum)
{
auto const size_expected = 62;
auto const size_expected = 63;
auto bucket_max = std::max<size_t> (1u, maximum / size_expected);
auto build_region = [&] (uint128_t const & begin, uint128_t const & end, size_t count) {
auto width = (end - begin) / count;
Expand All @@ -36,7 +36,8 @@ void nano::scheduler::buckets::setup_buckets (uint64_t maximum)
buckets_m.push_back (std::make_unique<scheduler::bucket> (begin + i * width, bucket_max));
}
};
build_region (0, uint128_t{ 1 } << 88, 1);
build_region (0, uint128_t{ 1 } << 79, 1);
build_region (uint128_t{ 1 } << 79, uint128_t{ 1 } << 88, 1);
build_region (uint128_t{ 1 } << 88, uint128_t{ 1 } << 92, 2);
build_region (uint128_t{ 1 } << 92, uint128_t{ 1 } << 96, 4);
build_region (uint128_t{ 1 } << 96, uint128_t{ 1 } << 100, 8);
Expand Down

0 comments on commit 59f6b31

Please sign in to comment.