Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(consensus): implement transaction flow script and update contracts #762

Merged
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
9e53c32
feat: add hardhat node and web3 package
mpaya5 Nov 19, 2024
b0c3ca8
feat: add contract and try script
kstroobants Nov 19, 2024
0f980b5
feat: setup contract compilation and artifact handling
mpaya5 Nov 19, 2024
dcaaad3
feat: creating hardhat transactions in consensus mechanism
kstroobants Nov 20, 2024
ab26ff3
feat: put hardhat port in env
kstroobants Nov 20, 2024
eb2427f
feat: remove rollup transactions database table
kstroobants Nov 20, 2024
8068b0c
feat: free transactions on hardhat, one hardhat account
kstroobants Nov 21, 2024
6d563e6
test: add hardhat test with code from the transaction_processor
kstroobants Nov 21, 2024
ace6439
fix: resolve pre-commit error
kstroobants Nov 21, 2024
577f716
test: moved test to integration tests, upgrade web3 version in requir…
kstroobants Nov 21, 2024
aa10179
feat(hardhat): add genlayer-consensus contracts and setup compilation
mpaya5 Nov 27, 2024
02df53c
fix: database migrations and hardhat security
mpaya5 Nov 28, 2024
4505246
feat: deleted amm_adaptive.py
mpaya5 Nov 28, 2024
fd0b7fb
fix: contract interaction
mpaya5 Nov 28, 2024
86a268c
fix: pre-commit errors solved
mpaya5 Nov 28, 2024
655ece3
fix: solved black pre-commit issue
mpaya5 Nov 28, 2024
a5f713b
feat(hardhat): add deployment persistence to hardhat node
mpaya5 Dec 4, 2024
84e3299
merged main branch
mpaya5 Dec 4, 2024
73b4c3d
merging main
mpaya5 Dec 4, 2024
ba242af
Merge branch 'main' into feat/add-persistence-to-hardhat-node-and-dep…
mpaya5 Dec 4, 2024
6d791c6
Merge branch 'main' into feat/add-persistence-to-hardhat-node-and-dep…
mpaya5 Dec 5, 2024
a9ab9af
refactor(hardhat): integrate start script into Dockerfile
mpaya5 Dec 5, 2024
2640c2e
fix(db): remove duplicate ghost_contract_address assignment
mpaya5 Dec 5, 2024
c00165d
fix(security): address SonarCloud warnings and improve test coverage
mpaya5 Dec 5, 2024
60648d5
Merge branch 'main' into feat/add-persistence-to-hardhat-node-and-dep…
mpaya5 Dec 5, 2024
be41109
Merge branch 'main' into feat/add-persistence-to-hardhat-node-and-dep…
mpaya5 Dec 5, 2024
8806dd1
Merge branch 'main' into feat/add-persistence-to-hardhat-node-and-dep…
mpaya5 Dec 9, 2024
e5c092c
commit: Add contract initialization and consensus service integration
mpaya5 Dec 9, 2024
cee6711
feat(deploy): integrate contract deployment and backend service
mpaya5 Dec 10, 2024
543a9c0
Merge branch 'main' into feat/add-rollup-consensus-service
mpaya5 Dec 10, 2024
5e701e2
Merged into current branch.
mpaya5 Dec 10, 2024
08530f5
Merge branch 'main' into feat/add-rollup-consensus-service
mpaya5 Dec 10, 2024
0488f78
feat(hardhat): implement contract deployment flow and deployment back…
mpaya5 Dec 11, 2024
91a837a
Merge remote-tracking branch 'refs/remotes/origin/feat/add-rollup-con…
mpaya5 Dec 11, 2024
c8b7616
merged main
mpaya5 Dec 11, 2024
a3f707e
feat(hardhat): implement contract deployment flow and deployment back…
mpaya5 Dec 11, 2024
1f94393
refactor: remove ghost_contract_address redundant references
mpaya5 Dec 11, 2024
304e355
Merge branch 'main' into feat/add-rollup-consensus-service
mpaya5 Dec 12, 2024
954e2c1
refactor: replace hardhat-deploy with hardhat-ignition
mpaya5 Dec 12, 2024
fe2aef8
refactor: remove deployFixture from consensus_service.py
mpaya5 Dec 12, 2024
ad15abb
feat(rpc): add eth_getContract endpoint to retrieve deployed contract…
mpaya5 Dec 13, 2024
18eac0f
refactor(consensus): remove unused methods from ConsensusService
mpaya5 Dec 13, 2024
6e18fa6
feat(rpc): enhance eth_getContract endpoint with ABI and message hand…
mpaya5 Dec 13, 2024
0749d2e
Merge branch 'main' into feat/api-add-endpoint-to-retrieve-consensus-…
mpaya5 Dec 16, 2024
c6f31fd
feat(hardhat): add bytecode to contract deployment data
mpaya5 Dec 16, 2024
269412e
Merge branch 'feat/api-add-endpoint-to-retrieve-consensus-contract-ad…
mpaya5 Dec 16, 2024
753f911
refactor: delete msg_handler in ConsensusService
mpaya5 Dec 16, 2024
64b8137
refactor: delete msg_handler in ConsensusService
mpaya5 Dec 16, 2024
2122bd7
refactor: delete msg_handler in ConsensusService
mpaya5 Dec 16, 2024
f0c2eda
feat: enable transaction submission to node in transactions_processor
mpaya5 Dec 16, 2024
23c08db
Merge branch 'main' into feat/send-consensus-tx-to-hardhat-network
mpaya5 Dec 16, 2024
cc2fdf9
Merge branch 'main' into feat/send-consensus-tx-to-hardhat-network
cristiam86 Dec 18, 2024
b43e17c
feat(consensus): Integrate create_rollup_transactions in consensus ex…
mpaya5 Dec 18, 2024
b80b5bd
feat(consensus): Integrate create_rollup_transactions in consensus ex…
mpaya5 Dec 18, 2024
1f669a4
fix: used pre-commit
mpaya5 Dec 18, 2024
1d0e701
fix: encapsule send_raw_transactions into a try-except block
mpaya5 Dec 18, 2024
59bad83
feat(consensus): implement transaction flow script and update contracts
mpaya5 Dec 18, 2024
2af9ec7
refactor: deleted changes that is not needed for that PR
mpaya5 Dec 18, 2024
5b9b2a0
refactor: deleted changes that is not needed for that PR
mpaya5 Dec 18, 2024
fd4b082
refactor: added more time in the healthcheck
mpaya5 Dec 18, 2024
ca0aedf
refactor: returned back the Docker and DockerCompose stable version
mpaya5 Dec 18, 2024
b0a7286
hore(docker): adjust healthcheck timing parameters
mpaya5 Dec 18, 2024
b3f165f
Merge branch 'main' into feat/consensus-update-contracts-and-add-tran…
cristiam86 Dec 19, 2024
e942e36
Merge branch 'main' into feat/consensus-update-contracts-and-add-tran…
cristiam86 Dec 19, 2024
17f75e0
refactor: add more time in the Hardhat healthcheck
mpaya5 Dec 19, 2024
d6ffede
fix: changes healtcheck parameters, change Dockerfile permissons
mpaya5 Dec 20, 2024
627d790
fix: changes healtcheck parameters, change Dockerfile permissons
mpaya5 Dec 20, 2024
249027e
fix(ci): adjust hardhat healthcheck timing parameters
mpaya5 Dec 20, 2024
f510429
fix: change healthcheck params hardhat test
kstroobants Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 40s
timeout: 15s
retries: 20
start_period: 40s

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
Loading