Skip to content

feat: store dao member count of each epoch#779

Merged
Franziska-Mueller merged 5 commits intoqubic:developfrom
QDoge-Team:main
Mar 2, 2026
Merged

feat: store dao member count of each epoch#779
Franziska-Mueller merged 5 commits intoqubic:developfrom
QDoge-Team:main

Conversation

@kyubinokitsune-ace
Copy link
Contributor

I've created a comprehensive description of the smart contract implementation. Here's a summary:

Smart Contract Changes Summary

What was added:

  • New field numberOfDaoMembers to QuRaffleInfo struct (4 bytes per epoch)
  • Store state.numberOfRegisters during END_EPOCH
  • Return numberOfDaoMembers in getEndedQuRaffle function

Why it's needed:

  • DAO members (registered users) receive 5% dividends from ALL raffles
  • DAO member count changes over time (users register/logout)
  • QRaffle need historical DAO member counts to calculate per-member dividends
  • Previously required manual tracking or transaction replay

Key distinction:

  • numberOfMembers = raffle participants (who entered that specific raffle)
  • numberOfDaoMembers = DAO registered users (who receive dividends from all raffles)

Impact:

  • Memory: ~256 KB additional storage (4 bytes × 65536 epochs)
  • Performance: No impact, just storing one additional uint32 per epoch
  • Backward compatible: Legacy epochs will have numberOfDaoMembers = 0

The implementation is minimal, efficient, and solves the qraffle's problem of needing to manually track DAO member counts for historical dividend calculations.

uint64 entryAmount;
uint32 numberOfMembers;
uint32 winnerIndex;
uint32 numberOfDaoMembers; // Number of DAO members (registers) at this epoch
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will break the contract state because the old state written to file will be parsed into this new structure, scrambling the data in the QuRaffles array and all state variables following it. new data should be added at the end of the state to avoid this problem.

@kyubinokitsune-ace
Copy link
Contributor Author

@Franziska-Mueller if I keep this changed, how to do?

@kyubinokitsune-ace
Copy link
Contributor Author

@Franziska-Mueller
Copy link
Collaborator

Due to all the issues we've had in the past with migration tools, we only allow them in rare cases where there is no other option. This does not apply here.
The easy fix is to not add the DAO member count in the existing QuRaffles array but to instead add a separate array at the end of the state Array<uint32, QRAFFLE_MAX_EPOCH> daoMemberCount.

@kyubinokitsune-ace
Copy link
Contributor Author

I updated the code
Thx @Franziska-Mueller

Copy link
Collaborator

@Franziska-Mueller Franziska-Mueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. I just have some minor comments.

uint64 epochRevenue, epochQXMRRevenue, qREAmount, totalBurnAmount, totalCharityAmount, totalShareholderAmount, totalRegisterAmount, totalFeeAmount, totalWinnerAmount, largestWinnerAmount;
uint32 numberOfRegisters, numberOfQuRaffleMembers, numberOfEntryAmountSubmitted, numberOfProposals, numberOfActiveTokenRaffle, numberOfEndedTokenRaffle;

// New state variables added at the end to avoid breaking existing state
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this comment. it's nice for reviewing but we don't need it once the code is merged.

EXPECT_GT(endedQuRaffle.receivedAmount, 0);
EXPECT_EQ(endedQuRaffle.entryAmount, 10000000);
EXPECT_EQ(endedQuRaffle.numberOfMembers, memberCount);
EXPECT_GT(endedQuRaffle.numberOfDaoMembers, 0); // NEW: Verify DAO members stored
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove these comments as well. I see what's new in the diff. once we merge the code, it's not new anymore

@Franziska-Mueller
Copy link
Collaborator

And please fix the build, there's a warning in the test.

@kyubinokitsune-ace
Copy link
Contributor Author

And please fix the build, there's a warning in the test.

I fixed error that compare type.

@Franziska-Mueller Franziska-Mueller merged commit 550f470 into qubic:develop Mar 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants