Skip to content

Commit

Permalink
Merge branch 'main' into 715-record-transaction-consensus-history-in-…
Browse files Browse the repository at this point in the history
…database
  • Loading branch information
kstroobants authored Dec 30, 2024
2 parents df2596d + 3ff73e5 commit e6f6d48
Show file tree
Hide file tree
Showing 27 changed files with 1,556 additions and 203 deletions.
20 changes: 10 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ services:
ports:
- "${HARDHAT_PORT:-8545}:8545"
volumes:
- ./hardhat/contracts:/app/contracts:ro
- ./hardhat/scripts:/app/scripts:ro
- ./hardhat/test:/app/test:ro
- ./hardhat/hardhat.config.js:/app/hardhat.config.js:ro
- ./hardhat/deploy:/app/deploy:ro
- ./hardhat/scripts:/app/scripts:ro
- ./hardhat/contracts:/app/contracts
- ./hardhat/scripts:/app/scripts
- ./hardhat/test:/app/test
- ./hardhat/hardhat.config.js:/app/hardhat.config.js
- ./hardhat/deploy:/app/deploy
- ./hardhat/scripts:/app/scripts
- hardhat_artifacts:/app/artifacts
- hardhat_cache:/app/cache
- hardhat_deployments:/app/deployments
Expand All @@ -213,10 +213,10 @@ services:
restart: always
healthcheck:
test: ["CMD", "curl", "-X", "POST", "-H", "Content-Type: application/json", "--fail", "http://localhost:8545", "-d", '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}']
interval: 10s
timeout: 5s
retries: 10
start_period: 10s
interval: 60s
timeout: 30s
retries: 5
start_period: 60s

volumes:
hardhat_artifacts:
Expand Down
19 changes: 5 additions & 14 deletions docker/Dockerfile.hardhat
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
FROM node:22.12-alpine3.19

# Create non-root user
RUN addgroup -S hardhat-group && adduser -S hardhat-user -G hardhat-group
WORKDIR /app

# Install necessary packages and set up the environment
RUN apk add --no-cache curl g++ make netcat-openbsd python3 && \
mkdir -p /app && \
chown -R hardhat-user:hardhat-group /app
RUN apk add --no-cache curl g++ make netcat-openbsd python3

COPY ./hardhat/package*.json ./
RUN npm install --ignore-scripts
Expand All @@ -21,12 +17,9 @@ RUN mkdir -p /app/deployments/localhost && \
mkdir -p /app/artifacts/contracts && \
mkdir -p /app/cache && \
mkdir -p /app/ignition/deployments && \
chown -R hardhat-user:hardhat-group /app && \
chmod -R 755 /app && \
chmod -R 775 /app/deployments && \
chmod -R 775 /app/artifacts && \
chmod -R 775 /app/cache && \
chmod -R 775 /app/ignition/deployments
mkdir -p /app/scripts && \
mkdir -p /app/test && \
chmod -R 777 /app

ENV PATH="/app/node_modules/.bin:${PATH}"

Expand All @@ -44,6 +37,4 @@ RUN echo '#!/bin/sh' > /app/start.sh && \

EXPOSE 8545

USER hardhat-user

CMD ["/app/start.sh"]
CMD ["/app/start.sh"]
37 changes: 37 additions & 0 deletions hardhat/contracts/RandomnessUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";

library RandomnessUtils {
using ECDSA for bytes32;

/**
* @dev Updates a random seed by verifying a VRF proof signature and generating a new seed.
* @param vrfProof The signature proof provided by the signer
* @param currentSeed The current seed value to be used for verification
* @param signer The address that should have signed the message
* @return newSeed The newly generated random seed
*/
function updateRandomSeed(
bytes memory vrfProof,
uint256 currentSeed,
address signer
) internal pure returns (uint256) {
// Convert seed to bytes32 and create ethereum signed message hash
bytes32 seed = bytes32(currentSeed);
bytes32 hash = MessageHashUtils.toEthSignedMessageHash(seed);

// Verify the signature
address recoveredSigner = hash.recover(vrfProof);
// Comment next check if you want to skip signature verification
require(
recoveredSigner == signer,
"RandomnessUtils: Invalid signature"
);

// Generate and return new seed
return uint256(keccak256(vrfProof));
}
}
24 changes: 24 additions & 0 deletions hardhat/contracts/v2_contracts/Appeals.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";

contract Appeals is
Initializable,
Ownable2StepUpgradeable,
ReentrancyGuardUpgradeable,
AccessControlUpgradeable
{
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
bytes32 public constant VALIDATOR_ROLE = keccak256("VALIDATOR_ROLE");

receive() external payable {}

function initialize() public initializer {
__Ownable2Step_init();
__ReentrancyGuard_init();
__AccessControl_init();
}
}
122 changes: 122 additions & 0 deletions hardhat/contracts/v2_contracts/ConsensusData.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/Ownable2StepUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "./interfaces/ITransactions.sol";
import "./interfaces/IQueues.sol";
import "./interfaces/IConsensusMain.sol";
import "./interfaces/IMessages.sol";

contract ConsensusData is
Initializable,
Ownable2StepUpgradeable,
ReentrancyGuardUpgradeable,
AccessControlUpgradeable
{
ITransactions public transactions;
IQueues public queues;
IConsensusMain public consensusMain;
struct TransactionData {
// Basic transaction info
address sender;
address recipient;
uint256 numOfInitialValidators;
uint256 txSlot;
uint256 timestamp;
uint256 lastVoteTimestamp;
bytes32 randomSeed;
ITransactions.ResultType result;
bytes txData;
bytes txReceipt;
IMessages.SubmittedMessage[] messages;
// // Validator info
address[] validators;
bytes32[] validatorVotesHash;
ITransactions.VoteType[] validatorVotes;
// Queue info
IQueues.QueueType queueType;
uint256 queuePosition;
// // Status info
address activator;
address leader;
ITransactions.TransactionStatus status;
uint256 committedVotesCount;
uint256 revealedVotesCount;
}

receive() external payable {}

function initialize(
address _consensusMain,
address _transactions,
address _queues
) public initializer {
__Ownable2Step_init();
__ReentrancyGuard_init();
__AccessControl_init();

transactions = ITransactions(_transactions);
queues = IQueues(_queues);
consensusMain = IConsensusMain(_consensusMain);
}

function getTransactionData(
bytes32 _tx_id
) external view returns (TransactionData memory) {
ITransactions.Transaction memory transaction = transactions
.getTransaction(_tx_id);

address activator = consensusMain.txActivator(_tx_id);
uint validatorsCount = consensusMain.validatorsCountForTx(_tx_id);
address[] memory validators = consensusMain.getValidatorsForTx(_tx_id);
uint leaderIndex = consensusMain.txLeaderIndex(_tx_id);
address leader = validatorsCount > 0
? validators[leaderIndex]
: address(0);

TransactionData memory txData = TransactionData({
// Basic transaction info
sender: transaction.sender,
recipient: transaction.recipient,
numOfInitialValidators: transaction.numOfInitialValidators,
txSlot: transaction.txSlot,
timestamp: transaction.timestamp,
lastVoteTimestamp: transaction.lastVoteTimestamp,
randomSeed: transaction.randomSeed,
result: transaction.result,
txData: transaction.txData,
txReceipt: transaction.txReceipt,
messages: transaction.messages,
// // Validator info
validators: transaction.validators,
validatorVotesHash: transaction.validatorVotesHash,
validatorVotes: transaction.validatorVotes,
// Queue info
queueType: queues.getTransactionQueueType(_tx_id),
queuePosition: queues.getTransactionQueuePosition(_tx_id),
// // Status info
activator: activator,
leader: leader,
status: consensusMain.txStatus(_tx_id),
committedVotesCount: consensusMain.voteCommittedCountForTx(_tx_id),
revealedVotesCount: consensusMain.voteRevealedCountForTx(_tx_id)
});

return txData;
}

// Setter functions
function setTransactions(address _transactions) external onlyOwner {
transactions = ITransactions(_transactions);
}

function setQueues(address _queues) external onlyOwner {
queues = IQueues(_queues);
}

function setConsensusMain(address _consensusMain) external onlyOwner {
consensusMain = IConsensusMain(_consensusMain);
}
}
Loading

0 comments on commit e6f6d48

Please sign in to comment.