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

Conversation

mpaya5
Copy link
Contributor

@mpaya5 mpaya5 commented Dec 18, 2024

Fixes #761

What

  • Added new consensus-flow.js script for transaction simulation
  • Updated consensus contracts to latest version
  • Refactored DeployFixture.js to match updated TransactionFlow.ts
  • Modified test suite to accommodate new contract flow

Why

  • Need to simulate transactions to test and develop indexer functionality
  • Previous contract versions TransactionFlow was not working properly
  • Required a script to directly interact with consensus flow for testing purposes

Testing done

  • Executed complete consensus flow through the new script
  • Verified all transaction steps (TransactionFlw):
    • Add Transaction
    • Activate Transaction
    • Propose Receipt
    • Commit Votes
    • Reveal Votes
    • Finalize Transaction
  • Verified integration with Docker environment
  • Added more tests in the deploy

Decisions made

  • Maintained compatibility with existing test suite structure
  • Added more tests to cover new flow
  • Created a script for iteracting with the deployed contracts to be able to generate transactions for testing purposes for the genlayer explorer

Checks

  • I have tested this code
  • I have reviewed my own PR
  • I have created an issue for this PR
  • I have set a descriptive PR title compliant with conventional commits

Reviewing tips

  • Focus on the consensus flow implementation in consensus-flow.js
  • Check validator setup in DeployFixture.js
  • Verify that all transaction steps are properly handled

User facing release notes

The genlayer-studio now includes a new script for simulating consensus transactions. This update follow new TransactionFlow updates and improves interaction with the genlayer_explorer indexer by generating transactions. Users can now test the complete consensus flow using the new consensus-flow.js script.

mpaya5 and others added 30 commits November 19, 2024 12:42
- Add Hardhat node service with Docker configuration
- Configure hardhat.config.js with local network settings
- Add 20 test accounts with 10,000 ETH each
- Add web3 Python package to backend requirements
- Update .gitignore for Hardhat artifacts and cache
- Add contract compilation setup with hardhat
- Configure project structure for smart contracts
- Fix file path for GhostContract.json artifact
- Add necessary dependencies for contract compilation
- Setup directory structure for contracts and artifacts
- Moved web3 python package into backend requirements file
- Added access to compiled hardhat contract in jsonrpc service
- Added database migration file so that a transaction has the ghost contract address of hardhat network
- When a genlayer contract is deployed then a hardhat contract is deployed, both are linked in the CurrentState table
- When a genlayer write method is executed then the new transaction gets the hardhat contract from the CurrentState table
- When a genlayer transaction changes from status then a rollup transaction is created on the hardhat network
- todo: remove rollup transaction table, put hardhat port in env, link genlayer account to hardhat account, check for out of gas, remove prints
- Add genlayer-consensus smart contracts to hardhat/contracts directory
- Update hardhat.config.js to enable new code generator (viaIR: true)
- Add @openzeppelin/contracts and @openzeppelin/contracts-upgradeable dependencies
- Configure hardhat Docker container for contract compilation
- Verify hardhat node functionality in genlayer-studio

This commit sets up the smart contract development environment with the
necessary dependencies and configurations to compile and deploy
genlayer-consensus contracts.
- Added migration for ghost_contract_address column in transactions table
- Fixed security issues in hardhat docker configuration
- Ensured proper migration sequence (0d9538be0318 -> cb34b6b353ed)

Migration changes:
- Added new column ghost_contract_address (String, nullable) to transactions table
- Provided proper upgrade and downgrade paths
- Verified migration execution and current head state

TODO: Frontend issues to fix:
- Methods panel not opening after transaction acceptance
- Need to investigate UI response after successful transactions
- Deleted amm_adaptive.py because is not using the new syntax

I will upload the new amm_adaptive.py whenevir will be ready
- Fixed contract deployment state updates for frontend synchronization
- Improved contract method interactions and state management
- Ensured proper state updates after contract value changes
- Add volume mappings for deployments, artifacts and cache
- Implement manual deployment file saving
- Update hardhat configuration for proper deployment paths

This change ensures that deployed contracts persist between container
restarts by saving deployment data to mounted volumes.

Note: Block persistence still requires a different solution (Ganache/Geth/Besu)
as Hardhat Network doesn't support state persistence.

Related issue: #669
- Removed start.sh script
- Incorporated start script directly into Dockerfile for streamlined execution
Removes redundant assignment of ghost_contract_address in transaction_from_dict
function to improve code clarity and prevent potential inconsistencies
- Ensure non-root user is used in Dockerfile to enhance security
- Adjust permissions to avoid overly permissive access (777) on /app directories
- Add tests to cover deployment scripts, ensuring proper functionality and coverage
- Updated deploy_contracts.js to handle contract initialization after deployment
- Added initial ConsensusService integration into server.py
- Enhanced Dockerfile.hardhat with proper permissions and chainId handling
- Started implementation of consensus_service.py with basic contract interactions

Note: consensus_service.py still needs additional work for complete contract initialization and interaction methods.
Integrate complete contract deployment persistence in Hardhat and create ConsensusService for contract interaction.

- Add deployFixture to Hardhat deployment script to handle contract initialization
- Create ConsensusService class to interact with deployed contracts from backend
- Add deploy_fixture method to ConsensusService as fallback initialization option
- Ensure consistent contract initialization between Hardhat and backend
- Load contract artifacts and addresses in ConsensusService from deployment files

The deployFixture now handles all contract initialization during deployment, while
ConsensusService provides a Python interface to interact with the deployed contracts.
The deploy_fixture method in ConsensusService mirrors the Hardhat initialization
logic but is kept as a fallback option.
- Update consensus contracts to latest version
- Update deployFixture to match TransactionFlow
- Modify test suite for new contract flow
- Update hardhat container permissions
- Add consensus-flow.js for transaction simulation
@mpaya5 mpaya5 linked an issue Dec 18, 2024 that may be closed by this pull request
@mpaya5 mpaya5 self-assigned this Dec 18, 2024
@mpaya5 mpaya5 added enhancement New feature or request run-tests labels Dec 18, 2024
@mpaya5 mpaya5 requested a review from cristiam86 December 18, 2024 20:52
@mpaya5 mpaya5 requested review from cristiam86 and removed request for cristiam86 December 20, 2024 08:57
- Increase interval from 40s to 60s to allow more time between checks
- Extend timeout from 15s to 30s for slower environments
- Reduce retries from 20 to 5 but with longer intervals
- Increase start period from 40s to 60s for initial container setup
Copy link

codecov bot commented Dec 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 18.21%. Comparing base (add6a9e) to head (f510429).
Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #762      +/-   ##
==========================================
- Coverage   19.55%   18.21%   -1.35%     
==========================================
  Files         129      129              
  Lines       10006    10076      +70     
  Branches      319      302      -17     
==========================================
- Hits         1957     1835     -122     
- Misses       7964     8156     +192     
  Partials       85       85              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mpaya5 mpaya5 requested a review from cristiam86 December 20, 2024 15:22
@cristiam86 cristiam86 merged commit 3ff73e5 into main Dec 20, 2024
19 of 21 checks passed
Copy link
Contributor

🎉 This PR is included in version 0.32.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(consensus): update contracts and add transaction flow script
3 participants