diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 0000000..7709711 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,121 @@ +name: Bug Report +description: File a bug report to help us improve +title: "[Bug]: " +labels: ["bug", "triage"] +assignees: [] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! ๐Ÿ› + + Please search existing issues before creating a new one to avoid duplicates. + + - type: input + id: mitosis-version + attributes: + label: Mitosis Chain Version + description: What version of Mitosis Chain are you running? + placeholder: v1.0.0 or commit hash + validations: + required: true + + - type: dropdown + id: environment + attributes: + label: Environment + description: What environment are you running on? + options: + - Localnet + - Devnet + - Testnet + - Mainnet + - Custom + validations: + required: true + + - type: input + id: os + attributes: + label: Operating System + description: What operating system are you using? + placeholder: Ubuntu 22.04, macOS 13.5, Windows 11, etc. + validations: + required: true + + - type: input + id: go-version + attributes: + label: Go Version + description: What version of Go are you using? + placeholder: go version go1.21.5 linux/amd64 + validations: + required: false + + - type: textarea + id: what-happened + attributes: + label: What happened? + description: A clear and concise description of what the bug is. + placeholder: Describe the bug... + validations: + required: true + + - type: textarea + id: expected-behavior + attributes: + label: Expected Behavior + description: What did you expect to happen? + placeholder: Describe what you expected to happen... + validations: + required: true + + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to Reproduce + description: Please provide detailed steps to reproduce the issue. + placeholder: | + 1. Run command `...` + 2. Set configuration `...` + 3. Observe error `...` + validations: + required: true + + - type: textarea + id: logs + attributes: + label: Logs + description: Please copy and paste any relevant log output. + render: shell + placeholder: Paste your logs here... + validations: + required: false + + - type: textarea + id: config + attributes: + label: Configuration + description: Please provide relevant configuration files or settings. + render: yaml + placeholder: Paste your configuration here... + validations: + required: false + + - type: textarea + id: additional-context + attributes: + label: Additional Context + description: Add any other context about the problem here. + placeholder: Any additional information that might be helpful... + validations: + required: false + + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our Code of Conduct + options: + - label: I agree to follow this project's Code of Conduct + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml new file mode 100644 index 0000000..91aaa8c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/documentation.yml @@ -0,0 +1,102 @@ +name: Documentation +description: Report missing, unclear, or incorrect documentation +title: "[Docs]: " +labels: ["documentation", "good first issue"] +assignees: [] +body: + - type: markdown + attributes: + value: | + Thanks for helping us improve our documentation! ๐Ÿ“š + + Clear documentation is essential for a great developer experience. + + - type: dropdown + id: doc-type + attributes: + label: Documentation Type + description: What type of documentation needs improvement? + options: + - README + - API Documentation + - Setup Guide + - CLI Documentation + - Code Comments + - Tutorial + - FAQ + - Other + validations: + required: true + + - type: input + id: page-url + attributes: + label: Documentation Page/File + description: Link to the documentation page or file path that needs improvement + placeholder: https://docs.mitosis.org/... or path/to/file.md + validations: + required: false + + - type: dropdown + id: issue-type + attributes: + label: Issue Type + description: What kind of documentation issue is this? + options: + - Missing documentation + - Incorrect information + - Unclear instructions + - Outdated content + - Typo/Grammar + - Broken links + - Missing examples + - Poor organization + validations: + required: true + + - type: textarea + id: current-content + attributes: + label: Current Content + description: What does the current documentation say? (copy/paste relevant sections) + render: markdown + placeholder: Paste current documentation content here... + validations: + required: false + + - type: textarea + id: suggested-improvement + attributes: + label: Suggested Improvement + description: How should the documentation be improved? + placeholder: The documentation should explain... + validations: + required: true + + - type: textarea + id: context + attributes: + label: Additional Context + description: | + Why is this improvement needed? What confusion does the current documentation cause? + placeholder: This would help developers who... + validations: + required: false + + - type: checkboxes + id: contribution + attributes: + label: Contribution + description: Would you like to contribute to fixing this documentation issue? + options: + - label: I'd like to work on this documentation improvement + required: false + + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our Code of Conduct + options: + - label: I agree to follow this project's Code of Conduct + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 0000000..e89e3a7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,109 @@ +name: Feature Request +description: Suggest an idea for this project +title: "[Feature]: " +labels: ["enhancement", "triage"] +assignees: [] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to suggest a new feature! ๐Ÿš€ + + Please search existing issues and discussions before creating a new feature request. + + - type: textarea + id: problem + attributes: + label: Is your feature request related to a problem? + description: A clear and concise description of what the problem is. + placeholder: I'm always frustrated when... + validations: + required: false + + - type: textarea + id: solution + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + placeholder: I would like... + validations: + required: true + + - type: textarea + id: alternatives + attributes: + label: Describe alternatives you've considered + description: A clear and concise description of any alternative solutions or features you've considered. + placeholder: I've also considered... + validations: + required: false + + - type: dropdown + id: feature-type + attributes: + label: Feature Type + description: What type of feature is this? + options: + - CLI Enhancement + - Consensus Layer + - EVM Integration + - Performance Improvement + - Developer Experience + - Documentation + - Testing + - Infrastructure + - Security + - Other + validations: + required: true + + - type: dropdown + id: priority + attributes: + label: Priority + description: How important is this feature to you? + options: + - Nice to have + - Important + - Critical + validations: + required: true + + - type: textarea + id: use-cases + attributes: + label: Use Cases + description: Describe specific use cases where this feature would be beneficial. + placeholder: | + - As a validator operator, I want to... + - As a developer, I need to... + - As a user, I would like to... + validations: + required: true + + - type: textarea + id: implementation + attributes: + label: Implementation Ideas + description: If you have ideas about how this could be implemented, please share them. + placeholder: This could be implemented by... + validations: + required: false + + - type: textarea + id: additional-context + attributes: + label: Additional Context + description: Add any other context, screenshots, or examples about the feature request here. + placeholder: Any additional information... + validations: + required: false + + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our Code of Conduct + options: + - label: I agree to follow this project's Code of Conduct + required: true \ No newline at end of file diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..1184de4 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,101 @@ +## Summary + + + +## Type of Change + + + +- [ ] ๐Ÿ› Bug fix (non-breaking change which fixes an issue) +- [ ] โœจ New feature (non-breaking change which adds functionality) +- [ ] ๐Ÿ’ฅ Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] ๐Ÿ“š Documentation update +- [ ] ๐ŸŽจ Code style/refactoring (no functional changes) +- [ ] โšก Performance improvement +- [ ] ๐Ÿ”ง Chore (maintenance, dependencies, etc.) +- [ ] ๐Ÿงช Test improvements + +## Changes Made + + + +- +- +- + +## Related Issues + + + +Fixes #(issue number) + +## Testing + + + +### Test Environment +- [ ] Localnet +- [ ] Devnet +- [ ] Testnet + +### Test Commands +```bash +# Add the commands you used to test +make test +make test-integration +``` + +### Test Results + + +## Breaking Changes + + + +- [ ] No breaking changes +- [ ] Breaking changes (describe below) + + + +## Checklist + + + +### Code Quality +- [ ] My code follows the project's style guidelines +- [ ] I have performed a self-review of my code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] My changes generate no new warnings + +### Testing +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] I have tested the changes on localnet/devnet + +### Documentation +- [ ] I have made corresponding changes to the documentation +- [ ] I have updated the CLI help text if applicable +- [ ] I have added/updated code comments where necessary + +### Dependencies +- [ ] I have checked that no new dependencies were introduced unnecessarily +- [ ] All dependencies are properly licensed and documented + +## Screenshots/Demos + + + +## Additional Notes + + + +## Reviewer Guidelines + + + +Please ensure: +- [ ] Code follows project conventions +- [ ] Changes are well-tested +- [ ] Documentation is updated +- [ ] Breaking changes are clearly documented +- [ ] Security implications are considered \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml new file mode 100644 index 0000000..5d20026 --- /dev/null +++ b/.github/workflows/benchmark.yml @@ -0,0 +1,30 @@ +name: Benchmark + +on: + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + benchmark: + name: Performance Benchmark + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Run benchmarks + run: | + go test -bench=. -benchmem -run=^$ ./... > benchmark.txt + echo "๐Ÿ“Š Benchmark Results:" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + cat benchmark.txt >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8cc2458 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,44 @@ +name: Build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Build binaries + env: + GOOS: linux + GOARCH: amd64 + run: | + # Build mitosisd + go build -o build/mitosisd-${GOOS}-${GOARCH} ./cmd/mitosisd + + # Build mito CLI + go build -o build/mito-${GOOS}-${GOARCH} ./cmd/mito + + # Build midevtool + go build -o build/midevtool-${GOOS}-${GOARCH} ./cmd/midevtool + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: binaries-linux-amd64 + path: build/* \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..6dc31b6 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +name: Lint + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + # Add permissions for checks + checks: write + pull-requests: write + +jobs: + lint: + name: Code Linting + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: '.go-version' + cache: true + + - name: Run golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: latest + args: --timeout=10m --config=.golangci.yml + + - name: Verify dependencies + run: | + go mod tidy + git diff --exit-code go.mod go.sum \ No newline at end of file diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml new file mode 100644 index 0000000..1aa17e2 --- /dev/null +++ b/.github/workflows/quality-gate.yml @@ -0,0 +1,150 @@ +name: Quality Gate + +on: + # Only run after other workflows complete + workflow_run: + workflows: ["Lint", "Test", "Security", "Build"] + types: [completed] + branches: [main] + # Also run on PR events, but with a delay to wait for other checks + pull_request: + branches: [main] + +permissions: + contents: read + checks: read + actions: read + +jobs: + quality-gate: + name: Quality Gate Check + runs-on: ubuntu-latest + steps: + - name: Wait for required checks + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const sha = context.payload.pull_request?.head?.sha || context.sha; + + console.log(`๐Ÿ” Checking quality gate for commit: ${sha}`); + console.log(`๐Ÿ“‹ Event: ${context.eventName}`); + + // Define required check runs (job names from workflows) + const requiredChecks = [ + 'Code Linting', // from lint.yml + 'Test Suite', // from test.yml + 'Security Scan', // from security.yml + 'Dependency Vulnerability Check', // from security.yml + ]; + + console.log(`๐Ÿ“‹ Required checks: ${requiredChecks.join(', ')}`); + + // Wait for checks with timeout + const maxWaitMinutes = 20; + const checkIntervalSeconds = 30; + const maxAttempts = (maxWaitMinutes * 60) / checkIntervalSeconds; + + let attempt = 0; + let allPassed = false; + + while (attempt < maxAttempts && !allPassed) { + attempt++; + console.log(`\n๐Ÿ”„ Attempt ${attempt}/${maxAttempts}`); + + try { + // Get check runs for this commit + const { data: checkRuns } = await github.rest.checks.listForRef({ + owner, + repo, + ref: sha, + per_page: 100 + }); + + const relevantChecks = checkRuns.check_runs.filter(check => + requiredChecks.includes(check.name) + ); + + console.log(`๐Ÿ“Š Found ${relevantChecks.length}/${requiredChecks.length} required checks`); + + // Check status of each required check + const checkStatus = {}; + const pendingChecks = []; + const failedChecks = []; + + for (const checkName of requiredChecks) { + const check = relevantChecks.find(c => c.name === checkName); + + if (!check) { + checkStatus[checkName] = 'missing'; + pendingChecks.push(checkName); + } else if (check.status === 'completed') { + checkStatus[checkName] = check.conclusion; + if (check.conclusion !== 'success') { + failedChecks.push(`${checkName}: ${check.conclusion}`); + } + } else { + checkStatus[checkName] = check.status; + pendingChecks.push(checkName); + } + } + + // Log current status + console.log('\n๐Ÿ“ˆ Current check status:'); + for (const [name, status] of Object.entries(checkStatus)) { + const emoji = status === 'success' ? 'โœ…' : + status === 'failure' || status === 'error' ? 'โŒ' : + status === 'missing' ? 'โณ' : '๐ŸŸก'; + console.log(` ${emoji} ${name}: ${status}`); + } + + // Check if we're done + if (failedChecks.length > 0) { + console.log(`\nโŒ Quality Gate FAILED`); + console.log(`Failed checks: ${failedChecks.join(', ')}`); + core.setFailed(`Quality gate failed: ${failedChecks.join(', ')}`); + return; + } + + if (pendingChecks.length === 0) { + console.log(`\nโœ… Quality Gate PASSED - All checks successful!`); + allPassed = true; + break; + } + + console.log(`โณ Waiting for: ${pendingChecks.join(', ')}`); + + // Wait before next check + if (attempt < maxAttempts) { + console.log(`โฑ๏ธ Waiting ${checkIntervalSeconds}s before next check...`); + await new Promise(resolve => setTimeout(resolve, checkIntervalSeconds * 1000)); + } + + } catch (error) { + console.log(`โš ๏ธ Error checking status: ${error.message}`); + if (attempt === maxAttempts) { + core.setFailed(`Failed to check quality gate status: ${error.message}`); + return; + } + } + } + + if (!allPassed) { + console.log(`\nโฐ Quality Gate TIMEOUT after ${maxWaitMinutes} minutes`); + core.setFailed(`Quality gate timed out waiting for checks to complete`); + } + + - name: Quality Gate Summary + if: success() + run: | + echo "## โœ… Quality Gate Passed" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "All required quality checks have completed successfully:" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "- โœ… **Code Linting** - Code style and format validation" >> $GITHUB_STEP_SUMMARY + echo "- โœ… **Test Suite** - Unit and integration tests" >> $GITHUB_STEP_SUMMARY + echo "- โœ… **Security Scan** - Vulnerability scanning" >> $GITHUB_STEP_SUMMARY + echo "- โœ… **Dependency Check** - Dependency vulnerability check" >> $GITHUB_STEP_SUMMARY + echo "- โœ… **Build** - Cross-platform build verification" >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "๐ŸŽ‰ **This PR meets all quality standards and is ready for merge!**" >> $GITHUB_STEP_SUMMARY \ No newline at end of file diff --git a/.github/workflows/release-mito.yml b/.github/workflows/release-mito.yml new file mode 100644 index 0000000..cbd05e5 --- /dev/null +++ b/.github/workflows/release-mito.yml @@ -0,0 +1,150 @@ +name: Release Mito CLI + +on: + push: + tags: + - 'mito/v*' # mito CLI releases (mito/vX.Y.Z) + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + strategy: + matrix: + os: [linux, darwin] + arch: [amd64, arm64] + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Extract version + id: version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT + echo "VERSION=${TAG_NAME#mito/}" >> $GITHUB_OUTPUT + + - name: Build mito CLI + env: + GOOS: ${{ matrix.os }} + GOARCH: ${{ matrix.arch }} + VERSION: ${{ steps.version.outputs.VERSION }} + run: | + echo "๐Ÿ”จ Building mito CLI ${VERSION} for ${GOOS}-${GOARCH}" + go build -ldflags="-X main.version=${VERSION}" \ + -o build/mito-${GOOS}-${GOARCH} ./cmd/mito + + - name: Create checksums + run: | + cd build + for file in *; do + sha256sum "$file" > "$file.sha256" + done + + - name: Upload binaries + uses: actions/upload-artifact@v3 + with: + name: binaries-mito-${{ matrix.os }}-${{ matrix.arch }} + path: build/* + + create-release: + needs: release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract version + id: version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT + echo "VERSION=${TAG_NAME#mito/}" >> $GITHUB_OUTPUT + + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: Organize artifacts + run: | + mkdir -p release + find artifacts -type f -exec cp {} release/ \; + + - name: Generate changelog + id: changelog + run: | + # Get previous mito CLI tag + PREV_TAG=$(git tag --sort=-version:refname | grep -E '^mito/v[0-9]+\.[0-9]+\.[0-9]+' | grep -v "${{ steps.version.outputs.TAG_NAME }}" | head -n1) + + if [ -z "$PREV_TAG" ]; then + PREV_TAG=$(git rev-list --max-parents=0 HEAD) + fi + + echo "CHANGELOG<> $GITHUB_OUTPUT + echo "## What's Changed" >> $GITHUB_OUTPUT + echo "### CLI (mito) Changes" >> $GITHUB_OUTPUT + git log --pretty=format:"- %s (%h)" ${PREV_TAG}..HEAD -- cmd/mito/ >> $GITHUB_OUTPUT + echo "" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: release/* + body: | + # Mito CLI ${{ steps.version.outputs.VERSION }} + + Command-line interface for Mitosis Chain. Manage validators, transactions, and interact with the blockchain. + + ${{ steps.changelog.outputs.CHANGELOG }} + + ## ๐Ÿ“ฅ Installation + + ### Quick Install (Linux/macOS) + ```bash + VERSION="${{ steps.version.outputs.VERSION }}" COMPONENT="mito" \ + curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash + ``` + + ### Manual Download + Download the appropriate binary for your platform from the assets below: + + | Platform | Architecture | Download | + |----------|--------------|----------| + | Linux | x86_64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mito-linux-amd64) | + | Linux | ARM64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mito-linux-arm64) | + | macOS | x86_64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mito-darwin-amd64) | + | macOS | ARM64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mito-darwin-arm64) | + + ## ๐Ÿ” Verification + + All binaries include SHA256 checksums. Verify your download: + ```bash + sha256sum -c .sha256 + ``` + + ## ๐Ÿ“– Documentation + + - [CLI Reference](https://docs.mitosis.org/cli) + - [User Guide](https://docs.mitosis.org/guide) + - [Commands Reference](https://docs.mitosis.org/commands) + + ## ๐Ÿ†• What's New in This Release + + ${{ steps.changelog.outputs.CHANGELOG }} + draft: false + prerelease: ${{ contains(steps.version.outputs.VERSION, 'alpha') || contains(steps.version.outputs.VERSION, 'beta') || contains(steps.version.outputs.VERSION, 'rc') }} + generate_release_notes: true \ No newline at end of file diff --git a/.github/workflows/release-mitosisd.yml b/.github/workflows/release-mitosisd.yml new file mode 100644 index 0000000..5e09734 --- /dev/null +++ b/.github/workflows/release-mitosisd.yml @@ -0,0 +1,188 @@ +name: Release Mitosisd + +on: + push: + tags: + - 'v*' # mitosisd releases (vX.Y.Z) + +permissions: + contents: write + packages: write + +jobs: + release: + runs-on: ubuntu-latest + strategy: + matrix: + os: [linux, darwin] + arch: [amd64, arm64] + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Extract version + id: version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT + echo "VERSION=${TAG_NAME}" >> $GITHUB_OUTPUT + + - name: Build mitosisd + env: + GOOS: ${{ matrix.os }} + GOARCH: ${{ matrix.arch }} + VERSION: ${{ steps.version.outputs.VERSION }} + run: | + echo "๐Ÿ”จ Building mitosisd ${VERSION} for ${GOOS}-${GOARCH}" + go build -ldflags="-X main.version=${VERSION} -X github.com/cosmos/cosmos-sdk/version.Version=${VERSION}" \ + -o build/mitosisd-${GOOS}-${GOARCH} ./cmd/mitosisd + + - name: Create checksums + run: | + cd build + for file in *; do + sha256sum "$file" > "$file.sha256" + done + + - name: Upload binaries + uses: actions/upload-artifact@v3 + with: + name: binaries-mitosisd-${{ matrix.os }}-${{ matrix.arch }} + path: build/* + + create-release: + needs: release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Extract version + id: version + run: | + TAG_NAME=${GITHUB_REF#refs/tags/} + echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_OUTPUT + echo "VERSION=${TAG_NAME}" >> $GITHUB_OUTPUT + + - name: Download all artifacts + uses: actions/download-artifact@v3 + with: + path: artifacts + + - name: Organize artifacts + run: | + mkdir -p release + find artifacts -type f -exec cp {} release/ \; + + - name: Generate changelog + id: changelog + run: | + # Get previous mitosisd tag + PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | grep -v "${{ steps.version.outputs.TAG_NAME }}" | head -n1) + + if [ -z "$PREV_TAG" ]; then + PREV_TAG=$(git rev-list --max-parents=0 HEAD) + fi + + echo "CHANGELOG<> $GITHUB_OUTPUT + echo "## What's Changed" >> $GITHUB_OUTPUT + echo "### Node (mitosisd) Changes" >> $GITHUB_OUTPUT + git log --pretty=format:"- %s (%h)" ${PREV_TAG}..HEAD -- cmd/mitosisd/ app/ x/ >> $GITHUB_OUTPUT + echo "" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + - name: Create GitHub Release + uses: softprops/action-gh-release@v1 + with: + files: release/* + body: | + # Mitosis Chain Node (mitosisd) ${{ steps.version.outputs.VERSION }} + + The core blockchain node for Mitosis Chain. Handles consensus, networking, and blockchain state management. + + ${{ steps.changelog.outputs.CHANGELOG }} + + ## ๐Ÿ“ฅ Installation + + ### Quick Install (Linux/macOS) + ```bash + curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash + ``` + + ### Manual Download + Download the appropriate binary for your platform from the assets below: + + | Platform | Architecture | Download | + |----------|--------------|----------| + | Linux | x86_64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mitosisd-linux-amd64) | + | Linux | ARM64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mitosisd-linux-arm64) | + | macOS | x86_64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mitosisd-darwin-amd64) | + | macOS | ARM64 | [Download](https://github.com/mitosis-org/chain/releases/download/${{ steps.version.outputs.TAG_NAME }}/mitosisd-darwin-arm64) | + + ## ๐Ÿ” Verification + + All binaries include SHA256 checksums. Verify your download: + ```bash + sha256sum -c .sha256 + ``` + + ## ๐Ÿ“– Documentation + + - [Setup Guide](https://docs.mitosis.org/setup) + - [Node Operation Guide](https://docs.mitosis.org/node) + - [Upgrade Guide](https://docs.mitosis.org/upgrade) + + ## ๐Ÿ†• What's New in This Release + + ${{ steps.changelog.outputs.CHANGELOG }} + draft: false + prerelease: ${{ contains(steps.version.outputs.VERSION, 'alpha') || contains(steps.version.outputs.VERSION, 'beta') || contains(steps.version.outputs.VERSION, 'rc') }} + generate_release_notes: true + + docker: + needs: [create-release] + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/${{ github.repository }} + tags: | + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..94938a4 --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,86 @@ +name: Security + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + security-events: write + actions: read + id-token: write + checks: write + +jobs: + security-scan: + name: Security Scan + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Install Gosec + run: | + go install github.com/securego/gosec/v2/cmd/gosec@latest + + - name: Run Gosec Security Scanner + run: | + gosec -fmt sarif -out gosec.sarif ./... + continue-on-error: true + + - name: Add Security Training Context + if: always() && hashFiles('gosec.sarif') != '' + uses: SecureCodeWarrior/github-action-add-sarif-contextual-training@v1 + with: + inputSarifFile: gosec.sarif + outputSarifFile: gosec-with-training.sarif + continue-on-error: true + + - name: Upload SARIF file + if: always() && hashFiles('gosec-with-training.sarif') != '' && github.token != '' + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: gosec-with-training.sarif + category: gosec + continue-on-error: true + + - name: Upload Raw SARIF file (fallback) + if: always() && hashFiles('gosec.sarif') != '' && hashFiles('gosec-with-training.sarif') == '' && github.token != '' + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: gosec.sarif + category: gosec + continue-on-error: true + + - name: Run govulncheck + run: | + go install golang.org/x/vuln/cmd/govulncheck@latest + govulncheck ./... + continue-on-error: true + + dependency-check: + name: Dependency Vulnerability Check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: '.go-version' + cache: true + + - name: Check for known vulnerabilities + run: | + go install golang.org/x/vuln/cmd/govulncheck@latest + govulncheck ./... + continue-on-error: true \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..db18cb1 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,66 @@ +name: Test + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +permissions: + contents: read + +jobs: + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Read Go version + id: go-version + run: | + GO_VERSION=$(cat .go-version) + echo "version=$GO_VERSION" >> $GITHUB_OUTPUT + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: ${{ steps.go-version.outputs.version }} + cache: true + + - name: Run tests + run: | + go test -v -race -coverprofile=coverage.out ./... + + - name: Generate test coverage report + run: | + go tool cover -html=coverage.out -o coverage.html + + - name: Upload coverage reports + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: coverage.html + + # Commented out strict coverage check - now using Codecov for coverage reporting + # - name: Check test coverage + # if: matrix.go-version == '1.21' + # run: | + # COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//') + # echo "Total test coverage: ${COVERAGE}%" + # if (( $(echo "$COVERAGE < 60" | bc -l) )); then + # echo "โŒ Test coverage is below 60%" + # exit 1 + # else + # echo "โœ… Test coverage is above 60%" + # fi + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.out + flags: unittests + name: codecov-umbrella + fail_ci_if_error: false \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..4b33ce9 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +community@mitosis.org. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ec44933 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,240 @@ +# Contributing to Mitosis Chain + +Welcome to Mitosis Chain! We're excited to have you contribute to the next-generation modular blockchain infrastructure. This guide will help you get started with contributing to our project. + +## ๐ŸŽฏ Quick Start + +### Prerequisites + +- Go 1.21 or higher +- Node.js 18+ (for frontend tools) +- Git +- Docker (for running devnet) + +### Development Setup + +1. **Fork and Clone** + ```bash + git clone https://github.com/YOUR_USERNAME/chain.git + cd chain + git remote add upstream https://github.com/mitosis-org/chain.git + ``` + +2. **Setup Development Environment** + ```bash + # Fetch submodules + git submodule update --init --recursive + + # Setup localnet (for testing) + make setup-geth + make setup-mitosisd + ``` + +3. **Verify Installation** + ```bash + make test + make build + ``` + +## ๐Ÿ”„ Development Workflow + +### 1. Create a Feature Branch +```bash +git checkout -b feature/your-feature-name +``` + +### 2. Make Changes +- Write your code following our coding standards +- Add tests for new functionality +- Update documentation if needed + +### 3. Test Your Changes +```bash +# Run unit tests +make test + +# Run integration tests +make test-integration + +# Run linting +make lint + +# Test localnet setup +make localnet-test +``` + +### 4. Commit Your Changes +We follow [Conventional Commits](https://www.conventionalcommits.org/) specification: + +```bash +git commit -m "feat: add new validator management feature" +git commit -m "fix: resolve consensus layer sync issue" +git commit -m "docs: update API documentation" +git commit -m "test: add unit tests for evmvalidator module" +``` + +**Commit Types:** +- `feat`: New features +- `fix`: Bug fixes +- `docs`: Documentation changes +- `style`: Code style changes (formatting, etc.) +- `refactor`: Code refactoring +- `test`: Adding or updating tests +- `chore`: Build process or auxiliary tool changes + +### 5. Push and Create Pull Request +```bash +git push origin feature/your-feature-name +``` + +Then create a Pull Request through GitHub with: +- Clear title and description +- Reference any related issues +- Include screenshots/demos if applicable + +## ๐Ÿ“ Coding Standards + +### Go Code Style +- Follow the [official Go Code Review Comments](https://github.com/golang/go/wiki/CodeReviewComments) +- Use `gofmt` and `goimports` for formatting +- Write meaningful variable and function names +- Add comments for exported functions and complex logic + +### Solidity Code Style +- Follow our [Solidity Style Guide](.cursor/rules/shared-rules/solidity/reference/coinbase-style-guide.mdc) +- Use ERC7201 for storage patterns +- Implement comprehensive tests for all contracts + +### Project Structure +``` +chain/ +โ”œโ”€โ”€ app/ # Cosmos SDK app configuration +โ”œโ”€โ”€ cmd/ # CLI applications +โ”œโ”€โ”€ x/ # Custom Cosmos SDK modules +โ”œโ”€โ”€ types/ # Common types +โ”œโ”€โ”€ proto/ # Protocol buffer definitions +โ”œโ”€โ”€ infra/ # Infrastructure and deployment +โ””โ”€โ”€ scripts/ # Build and utility scripts +``` + +## ๐Ÿงช Testing Guidelines + +### Unit Tests +- Write tests for all new functions +- Aim for >80% code coverage +- Use table-driven tests where appropriate +- Mock external dependencies + +### Integration Tests +- Test module interactions +- Verify end-to-end workflows +- Include both happy path and error cases + +### Example Test Structure +```go +func TestValidatorCreation(t *testing.T) { + tests := []struct { + name string + input ValidatorInput + want Validator + wantErr bool + }{ + { + name: "valid validator creation", + input: ValidatorInput{...}, + want: Validator{...}, + wantErr: false, + }, + // Add more test cases + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // Test implementation + }) + } +} +``` + +## ๐Ÿ› Bug Reports + +When filing a bug report, please include: + +1. **Environment Information** + - Operating system and version + - Go version + - Mitosis Chain version + +2. **Steps to Reproduce** + - Clear, numbered steps + - Expected vs actual behavior + - Relevant logs or error messages + +3. **Additional Context** + - Screenshots if applicable + - Configuration files + - Related issues or PRs + +## ๐Ÿ’ก Feature Requests + +For new features: + +1. **Check existing issues** to avoid duplicates +2. **Describe the use case** and problem you're solving +3. **Propose a solution** with technical details +4. **Consider breaking changes** and backward compatibility + +## ๐Ÿ“– Documentation + +- Update relevant documentation with your changes +- Follow markdown best practices +- Include code examples where helpful +- Update the changelog for significant changes + +### Documentation Types +- **README.md**: Project overview and quick start +- **API Documentation**: Generated from code comments +- **User Guides**: Step-by-step instructions +- **Developer Guides**: Technical implementation details + +## ๐Ÿ” Code Review Process + +### For Contributors +- Respond to review feedback promptly +- Make requested changes in new commits +- Keep discussions focused and constructive + +### For Reviewers +- Be constructive and respectful +- Focus on code quality, security, and maintainability +- Approve when satisfied with the changes + +## ๐Ÿ† Recognition + +Contributors are recognized through: +- **Contributor list** in our README +- **Release notes** acknowledgments +- **Community highlights** in our social channels + +## ๐Ÿค Community Guidelines + +- Be respectful and inclusive +- Help newcomers get started +- Share knowledge and best practices +- Follow our [Code of Conduct](CODE_OF_CONDUCT.md) + +## ๐Ÿ†˜ Getting Help + +- **GitHub Discussions**: Technical questions and ideas +- **Discord**: Real-time community chat +- **Issues**: Bug reports and feature requests + +## ๐Ÿ“š Additional Resources + +- [Cosmos SDK Documentation](https://docs.cosmos.network/) +- [Go Documentation](https://golang.org/doc/) +- [Mitosis Chain Documentation](https://docs.mitosis.org/) + +--- + +Thank you for contributing to Mitosis Chain! Your efforts help build the future of modular blockchain infrastructure. ๐Ÿš€ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e77a1c2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,205 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(which shall not include communication that is conspicuously +marked or otherwise designated in writing by the copyright owner +as "Not a Work"). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based upon (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and derivative works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to use, reproduce, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Work, and to +permit persons to whom the Work is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Work. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or +Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices +stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works +that You distribute, all copyright, trademark, patent, +attribution and other notices from the Source form of the Work, +excluding those notices that do not pertain to any part of +the Derivative Works; and + +(d) If the Work includes a "NOTICE" file as part of its +distribution, then any Derivative Works that You distribute must +include a readable copy of the attribution notices contained +within such NOTICE file, excluding those notices that do not +pertain to any part of the Derivative Works, in at least one +of the following places: within a NOTICE file distributed +as part of the Derivative Works; within the Source form or +documentation, if provided along with the Derivative Works; or, +within a display generated by the Derivative Works, if and +wherever such third-party notices normally appear. The contents +of the NOTICE file are for informational purposes only and +do not modify the License. You may add Your own attribution +notices within Derivative Works that You distribute, alongside +or as an addendum to the NOTICE text from the Work, provided +that such additional attribution notices cannot be construed +as modifying the License. + +You may add Your own copyright notice to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Support. You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or support. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + +To apply the Apache License to your work, attach the following +boilerplate notice, with the fields enclosed by brackets "[]" +replaced with your own identifying information. (Don't include +the brackets!) The text should be enclosed in the appropriate +comment syntax for the file format. We also recommend that a +file or class name and description of purpose be included on the +same "printed page" as the copyright notice for easier +identification within third-party archives. + +Copyright [yyyy] [placeholder] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. \ No newline at end of file diff --git a/README.md b/README.md index ee4eb70..e06c244 100644 --- a/README.md +++ b/README.md @@ -1,187 +1,118 @@ -# Mitosis Chain +# mitosis -## Architecture +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) +[![Security](https://github.com/mitosis-org/chain/actions/workflows/security.yml/badge.svg?branch=main)](https://github.com/mitosis-org/chain/actions/workflows/security.yml) +[![Quality Gate](https://github.com/mitosis-org/chain/actions/workflows/quality-gate.yml/badge.svg?branch=main)](https://github.com/mitosis-org/chain/actions/workflows/quality-gate.yml) -### Overview +**Modular, contributor-friendly implementation of the Ethereum-compatible blockchain protocol** -![architecture.png](assets/architecture.png) +## What is Mitosis? -The Mitosis Chain employs a modular architecture that separates execution from consensus. +Mitosis is a new Ethereum-compatible blockchain implementation that is focused on being user-friendly, highly modular, as well as being fast and efficient. Mitosis is built on Cosmos SDK and is compatible with all Ethereum tooling and infrastructure. It features a unique modular architecture that separates execution from consensus, combining the best of both Ethereum and Cosmos ecosystems. -- The execution layer is fully EVM-compatible, enabling unmodified Ethereum execution clients to process transactions, manage state, and execute smart contracts. -- The consensus layer is built upon the Cosmos SDK and utilizes CometBFT for consensus. -- The two layers communicate with each other using [Engine API](https://hackmd.io/@danielrachi/engine_api). The consensus layer utilizes [Octane](https://github.com/omni-network/omni/tree/main/octane) for Engine API implementation. +## Goals -Most of our logic exists on the execution layer, while the consensus layer is kept thin by having only minimal code and responsibilities for consensus. +As a full Ethereum-compatible blockchain, Mitosis allows users to connect to the network and interact with smart contracts using familiar Ethereum tooling. Building a successful blockchain requires creating a high-quality implementation that is both secure and efficient, as well as being easy to use. It also requires building a strong community of contributors who can help support and improve the software. -### Validator & Governance System +More concretely, our goals are: -In most Cosmos SDK-based chains, validator and governance systems are built using `x/staking`, `x/slashing`, `x/distribution`, and `x/gov` modules provided by Cosmos SDK. -However, we don't use all of them. We implement most of the necessary logic as smart contracts in the EVM (execution layer). \ -For example: -- A user stakes and delegates $MITO to a validator on EVM. -- An operator creates and operates a validator on EVM. -- Staking rewards are distributed on EVM. -- For governance, users cast votes and proposals are executed on EVM. +1. **Modularity**: Every component of Mitosis is built to be used as a library: well-tested, heavily documented and benchmarked. We envision that developers will import the node's crates, mix and match, and innovate on top of them. -The contracts manage all user flows and serve as the source of truth. -Some information from the contracts is delivered to the consensus layer through EVM logs on `ConsensusValidatorEntrypoint` and `ConsensusGovernanceEntrypoint` contracts. -When an EVM block has been created and finalized on the consensus layer, the consensus layer parses and processes the EVM logs in the block. +2. **Performance**: Mitosis aims to be fast, leveraging the proven Cosmos SDK architecture with full EVM compatibility. We optimize for DeFi and cross-chain operations with minimal latency. -### Core Modules +3. **Free for anyone to use any way they want**: Mitosis is free open source software, built for the community, by the community. By licensing the software under the Apache license, we want developers to use it without being bound by business licenses. -#### `x/evmengine` (forked from Octane) +4. **EVM Compatibility**: Full compatibility with Ethereum tooling, wallets, and infrastructure. Run your Ethereum dApps without changes while leveraging advanced Cosmos features. -This module communicates with an execution client through Engine API and wraps an EVM block into one transaction in the consensus layer. -Note that there can only be one transaction wrapped from an EVM block, and other types of transactions are prohibited in a consensus block. \ -This module is forked from [Octane](https://github.com/omni-network/omni/tree/main/octane). There are limited changes from the upstream for seamless integration with `x/evmvalidator` and `x/evmgov`. +5. **Developer Experience**: Unified development experience using Solidity for all logic, standard Ethereum tooling, and familiar wallet integration. -#### `x/evmvalidator` +## Status -This module manages a validator set on the consensus layer. Note that there are no features such as delegation and reward distribution because those features are implemented in contracts on EVM. -Most states are managed in the EVM contracts, and this module simply applies validator set changes and consensus voting power updates delivered from `ConsensusValidatorEntrypoint`. \ -We could say this module is a lightweight version of `x/staking` that has EVM contracts as the source of truth. -This module also implements some parts of interfaces of `x/staking` to integrate with `x/slashing` and `x/evidence`. +Mitosis is under active development and is not yet ready for production use. We are working towards a stable release. -#### `x/evmgov` +## For Users -This module provides arbitrary message execution from EVM. Governance on EVM can trigger arbitrary message execution against consensus layer modules. It can be used for cases such as module parameter changes. -It is very lightweight compared to `x/gov` because there are no concepts such as proposals and voting power. -These concepts are implemented in EVM contracts, and this module simply executes arbitrary messages delivered from `ConsensusGovernanceEntrypoint`. +### Installation -## Setup +```bash +# Install latest release +curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash -We categorize environments for setup into: -- **Localnet** - - Localnet is for fast development and testing iterations in local environment. - - It runs a single validator for the mitosis chain. -- **Devnet** - - Devnet is for development and testing with complete form of the components. - - It runs two validator nodes and a non-validator node for the mitosis chain. +# Or download from releases +wget https://github.com/mitosis-org/chain/releases/latest/download/mitosisd-linux-amd64 +chmod +x mitosisd-linux-amd64 && mv mitosisd-linux-amd64 /usr/local/bin/mitosisd +``` -**Chain IDs** -- **Localnet** - - Chain ID (EVM): `124899` - - Chain ID (Cosmos SDK): `mitosis-localnet-1` -- **Devnet** - - Chain ID (EVM): `124864` - - Chain ID (Cosmos SDK): `mitosis-devnet-1` +### Running a Node -### Localnet +```bash +# Initialize node +mitosisd init my-node --chain-id mitosis-localnet-1 -You should run an execution client (`geth` or `reth`) and an consensus client (`mitosisd`) both. +# Start node +mitosisd start +``` +## For Developers -Pre-requisites +### Prerequisites -Make sure you have fetched the GitHub submodules: +- Go 1.24+ +- Git -```sh -git submodule update --init --recursive -``` +### Building from Source -Setup and run an execution client (`geth` or `reth`): +First, clone the repository: ```bash -# It initializes geth. If there was already initialized, it remove all old data and re-initialize it. -make setup-geth # or `make setup-reth` - -# Note that it just tries to use existing data instead of setting up geth automatically. -# You should run `setup-geth` if you haven't initialized geth yet or want to reset it. -make run-geth # or `make setup-reth` +git clone https://github.com/mitosis-org/chain +cd chain ``` -Setup and run an consensus client (`mitosisd`): -```bash -# It initializes mitosisd. If there was already initialized, it remove all old data and re-initialize it. -make setup-mitosisd - -# Note that it just tries to use existing data instead of setting up mitosisd automatically. -# You should run `setup-mitosisd` if you haven't initialized mitosisd yet or want to reset it. -make run-mitosisd -``` +Next, build the binary: -Remove all data (reset) of `geth` and `mitosisd`: ```bash -# Note that it won't be working as expected if you clean up only one of geth and mitosisd. -make clean-geth # or `make clean-reth` -make clean-mitosisd +make build ``` -Deploy & Setup consensus entrypoint contracts: +### Running Tests + ```bash -# Run this command in https://github.com/mitosis-org/protocol to deploy the consensus entrypoint contracts. -# The deployed address would be: -# - ConsensusGovernanceEntrypoint: 0x06c9918ff483fd88C65dD02E788427cfF04545b9 -# - ConsensusValidatorEntrypoint : 0x9866D79EF3e9c0c22Db2b55877013e13a60AD478 -./tools/deploy-consensus-entrypoints.sh - -# Note that `ConsensusGovernanceEntrypoint` address is managed in `app.toml`: -# [evmgov] -# entrypoint = "0x06c9918ff483fd88C65dD02E788427cfF04545b9" - -# Update `ConsensusValidatorEntrypoint` address in x/evmvalidator module. -./build/midevtool governance execute \ - --entrypoint 0x06c9918ff483fd88C65dD02E788427cfF04545b9 \ - --private-key 0x5a496832ac0d7a484e6996301a5511dbc3b723d037bc61261ecaf425bd6a5b37 \ - --msg '[{"@type":"/mitosis.evmvalidator.v1.MsgUpdateValidatorEntrypointContractAddr","authority":"mito1g86pactsvfrcglkvqzvdwkxhjshafu280q95p7","addr":"0x9866D79EF3e9c0c22Db2b55877013e13a60AD478"}]' +make test ``` -### Devnet +### Contributing -#### Build a dockerfile for mitosisd -```bash -make devnet-build -``` +If you want to contribute, or follow along with contributor discussion, you can use our GitHub discussions and issues. -#### Setup and run the mitosis chain -```bash -# Init a mitosis chain. -# It prepares a genesis file for the mitosis chain. -make devnet-init +- Our contributor guidelines can be found in [CONTRIBUTING.md](CONTRIBUTING.md). +- See our [Security Policy](SECURITY.md) for security-related contributions. -# Run nodes for a mitosis chain. -make devnet-up +## Getting Help -# Check the status of the nodes. -docker logs mitosis-devnet-node-mitosisd-1 -docker logs mitosis-devnet-node-reth-1 +If you have any questions: -# Check geth rpc is working properly. -cast block-number --rpc-url http://localhost:18545 -# You can use `curl` instead if `cast` is not installed. -curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":124864}' http://localhost:18545 -``` +- Open a discussion with your question, or +- Open an issue with the bug +- Check our documentation at [docs.mitosis.org](https://docs.mitosis.org) -#### Deploy consensus entrypoint contracts: -```bash -# Run this command in https://github.com/mitosis-org/protocol to deploy the consensus entrypoint contracts. -# The deployed address would be: -# - ConsensusGovernanceEntrypoint: 0x06c9918ff483fd88C65dD02E788427cfF04545b9 -# - ConsensusValidatorEntrypoint : 0x9866D79EF3e9c0c22Db2b55877013e13a60AD478 -RPC_URL="http://127.0.0.1:18545" ./tools/deploy-consensus-entrypoints.sh -``` +## Security -#### Create a validator for the mitosis chain -```bash -# It creates a validator for the `subval` node. -# Note that it setup `ConsensusValidatorEntrypoint` address automatically. -make devnet-create-validator -``` +See [SECURITY.md](SECURITY.md). -#### Stop the mitosis chain and reset the data -```bash -# It stops the nodes. -# You can start them again with keeping existing data through `make devnet-up`. -make devnet-down +## Acknowledgements -# It stops all nodes and removes all data of the nodes. -# It also removes the initialization data which is created by `make devnet-init`. -make devnet-clean -``` +Mitosis is built on the shoulders of giants. We would like to thank: + +- **Cosmos SDK**: For providing the robust blockchain framework that powers our consensus layer +- **CometBFT**: For the battle-tested Byzantine fault-tolerant consensus mechanism +- **Octane**: For the EVM-Engine API integration that enables our modular architecture +- **Ethereum**: For the EVM specification and the vibrant ecosystem that inspired this project + +## License -## Tools +Licensed under either of -### Validator Operations +- Apache License, Version 2.0, ([LICENSE](LICENSE) or http://www.apache.org/licenses/LICENSE-2.0) -For managing validators in the Mitosis network, please see the [MITO CLI documentation](cmd/mito/README.md). +at your option. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..aecfb91 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,104 @@ +# Security Policy + +## Supported Versions + +We actively support and provide security updates for the following versions of Mitosis Chain: + +| Version | Supported | +| ------- | ------------------ | +| main | :white_check_mark: | +| latest | :white_check_mark: | +| < 1.0 | :x: | + +## Reporting a Vulnerability + +The Mitosis Chain team takes security vulnerabilities seriously. We appreciate your efforts to responsibly disclose any vulnerabilities you find. + +### How to Report + +**Please do NOT report security vulnerabilities through public GitHub issues.** + +Instead, please report them via one of the following methods: + +1. **Email**: Send details to [security@mitosis.org](mailto:security@mitosis.org) +2. **GitHub Security Advisories**: Use the [private vulnerability reporting feature](https://github.com/mitosis-org/chain/security/advisories/new) + +### What to Include + +When reporting a vulnerability, please include: + +- Type of issue (e.g., buffer overflow, SQL injection, cross-site scripting, etc.) +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue, including how an attacker might exploit the issue + +### Response Timeline + +- **Initial Response**: We will acknowledge receipt of your vulnerability report within 48 hours +- **Investigation**: We will investigate and validate the vulnerability within 7 days +- **Resolution**: We will work on a fix and provide updates on our progress +- **Disclosure**: We will coordinate with you on the disclosure timeline + +### Responsible Disclosure + +We believe in responsible disclosure and ask that you: + +- Give us reasonable time to investigate and fix the issue before public disclosure +- Do not access, modify, or delete data that doesn't belong to you +- Do not perform any actions that could negatively impact other users +- Do not publicly disclose the vulnerability until we have addressed it + +### Security Features + +Mitosis Chain implements several security measures: + +- **Code Audits**: Regular security audits of critical components +- **Dependency Scanning**: Automated scanning for known vulnerabilities in dependencies +- **Static Analysis**: Continuous static code analysis for security issues +- **Access Controls**: Strict access controls for critical infrastructure +- **Encryption**: All sensitive data is encrypted at rest and in transit + +### Security Best Practices for Users + +When using Mitosis Chain, please follow these security best practices: + +1. **Keep Software Updated**: Always use the latest supported version +2. **Secure Private Keys**: Never share private keys or store them in unsecured locations +3. **Network Security**: Use secure networks and VPNs when possible +4. **Backup Strategy**: Implement proper backup strategies for critical data +5. **Monitor Activity**: Regularly monitor your validator and transaction activity + +### Security Advisories + +We will publish security advisories for any vulnerabilities that could affect users: + +- **GitHub Security Advisories**: Published on our GitHub repository +- **Community Channels**: Announced in our Discord and Telegram channels +- **Documentation**: Updated security guidance in our documentation + +### Bug Bounty Program + +We are planning to launch a bug bounty program to reward security researchers who help us identify vulnerabilities. Details will be announced soon. + +### Contact Information + +For security-related questions or concerns: + +- **Email**: [security@mitosis.org](mailto:security@mitosis.org) +- **PGP Key**: [Available here](https://keybase.io/mitosis/pgp_keys.asc) (Coming Soon) + +### Legal Safe Harbor + +Mitosis Labs will not pursue legal action against security researchers who: + +- Follow this responsible disclosure process +- Act in good faith +- Do not violate any laws +- Do not access or modify data beyond what is necessary to demonstrate the vulnerability + +--- + +Thank you for helping us keep Mitosis Chain secure! ๐Ÿ”’ \ No newline at end of file diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..92d9dfc --- /dev/null +++ b/codecov.yml @@ -0,0 +1,58 @@ +codecov: + require_ci_to_pass: yes + notify: + after_n_builds: 1 + +coverage: + precision: 2 + round: down + range: "50...100" + + status: + project: + default: + target: 60% + threshold: 1% + if_no_uploads: error + if_not_found: success + if_ci_failed: error + patch: + default: + target: 70% + threshold: 5% + if_no_uploads: error + if_not_found: success + if_ci_failed: error + +comment: + layout: "header, diff, flags, files, footer" + behavior: default + require_changes: false + require_base: no + require_head: yes + +ignore: + - "*.pb.go" + - "*.pulsar.go" + - "**/*_test.go" + - "**/testutil/**" + - "**/mock_*.go" + - "api/**" + - "proto/**" + - "test-keystore/**" + - "infra/**" + - "scripts/**" + - "dependencies/**" + +flags: + unittests: + carryforward: true + paths: + - "x/" + - "app/" + - "cmd/" + - "types/" + - "bindings/" + +github_checks: + annotations: true \ No newline at end of file diff --git a/go.mod b/go.mod index 92e6b6e..07f7255 100644 --- a/go.mod +++ b/go.mod @@ -34,6 +34,11 @@ require ( google.golang.org/protobuf v1.36.5 ) +require ( + github.com/pelletier/go-toml/v2 v2.2.2 + golang.org/x/term v0.29.0 +) + require ( cloud.google.com/go v0.112.1 // indirect cloud.google.com/go/compute/metadata v0.5.2 // indirect @@ -168,7 +173,6 @@ require ( github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a // indirect github.com/oklog/run v1.1.0 // indirect github.com/olekukonko/tablewriter v0.0.5 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect @@ -218,7 +222,6 @@ require ( golang.org/x/oauth2 v0.24.0 // indirect golang.org/x/sync v0.11.0 // indirect golang.org/x/sys v0.30.0 // indirect - golang.org/x/term v0.29.0 // indirect golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.9.0 // indirect google.golang.org/api v0.171.0 // indirect diff --git a/scripts/install.sh b/scripts/install.sh new file mode 100755 index 0000000..abf2769 --- /dev/null +++ b/scripts/install.sh @@ -0,0 +1,221 @@ +#!/bin/bash + +# Mitosis Chain Installation Script +# Usage: +# curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash +# COMPONENT=mito curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash + +set -e + +# Colors +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Configuration +REPO="mitosis-org/chain" +INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" +VERSION="${VERSION:-latest}" +COMPONENT="${COMPONENT:-mitosisd}" # Default to mitosisd, can be 'mito' + +# Utility functions +log() { + echo -e "${GREEN}[INFO]${NC} $1" +} + +warn() { + echo -e "${YELLOW}[WARN]${NC} $1" +} + +error() { + echo -e "${RED}[ERROR]${NC} $1" + exit 1 +} + +# Detect platform +detect_platform() { + local os arch + + case "$(uname -s)" in + Linux*) os="linux" ;; + Darwin*) os="darwin" ;; + *) error "Unsupported OS: $(uname -s)" ;; + esac + + case "$(uname -m)" in + x86_64) arch="amd64" ;; + arm64|aarch64) arch="arm64" ;; + *) error "Unsupported architecture: $(uname -m)" ;; + esac + + echo "${os}-${arch}" +} + +# Get latest release version for component +get_latest_version() { + local component="$1" + local version + + if [[ "$component" == "mito" ]]; then + # Get latest mito release (mito/vX.Y.Z) + version=$(curl -s "https://api.github.com/repos/${REPO}/releases" | \ + grep '"tag_name":' | \ + grep '"mito/' | \ + head -n1 | \ + cut -d'"' -f4 | \ + sed 's/mito\///') + else + # Get latest mitosisd release (vX.Y.Z) + version=$(curl -s "https://api.github.com/repos/${REPO}/releases" | \ + grep '"tag_name":' | \ + grep -v '"mito/' | \ + head -n1 | \ + cut -d'"' -f4) + fi + + if [[ -z "$version" ]]; then + error "Failed to get latest version for ${component}" + fi + echo "$version" +} + +# Get tag name for component and version +get_tag_name() { + local component="$1" + local version="$2" + + if [[ "$component" == "mito" ]]; then + echo "mito/${version}" + else + echo "${version}" + fi +} + +# Download and install binary +install_binary() { + local binary="$1" + local platform="$2" + local tag_name="$3" + local url="https://github.com/${REPO}/releases/download/${tag_name}/${binary}-${platform}" + + log "Downloading ${binary} from tag ${tag_name} for ${platform}..." + + # Create temporary directory + local temp_dir + temp_dir=$(mktemp -d) + cd "$temp_dir" + + # Download binary + if command -v curl >/dev/null 2>&1; then + curl -L -o "$binary" "$url" + elif command -v wget >/dev/null 2>&1; then + wget -O "$binary" "$url" + else + error "curl or wget is required" + fi + + # Download checksum + if command -v curl >/dev/null 2>&1; then + curl -L -o "${binary}.sha256" "${url}.sha256" + elif command -v wget >/dev/null 2>&1; then + wget -O "${binary}.sha256" "${url}.sha256" + fi + + # Verify checksum + if command -v sha256sum >/dev/null 2>&1; then + sha256sum -c "${binary}.sha256" || error "Checksum verification failed" + elif command -v shasum >/dev/null 2>&1; then + shasum -a 256 -c "${binary}.sha256" || error "Checksum verification failed" + else + warn "Cannot verify checksum: sha256sum or shasum not found" + fi + + # Make executable + chmod +x "$binary" + + # Install to target directory + if [[ -w "$INSTALL_DIR" ]]; then + mv "$binary" "$INSTALL_DIR/" + else + log "Installing to $INSTALL_DIR (requires sudo)" + sudo mv "$binary" "$INSTALL_DIR/" + fi + + # Cleanup + cd / + rm -rf "$temp_dir" + + log "Successfully installed ${binary} to ${INSTALL_DIR}/${binary}" +} + +# Main installation function +main() { + log "๐Ÿš€ Installing Mitosis Chain component: ${COMPONENT}" + + # Validate component + if [[ "$COMPONENT" != "mitosisd" && "$COMPONENT" != "mito" ]]; then + error "Invalid component: ${COMPONENT}. Must be 'mitosisd' or 'mito'" + fi + + # Check prerequisites + if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then + error "curl or wget is required" + fi + + # Detect platform + local platform + platform=$(detect_platform) + log "Detected platform: $platform" + + # Get version + if [[ "$VERSION" == "latest" ]]; then + VERSION=$(get_latest_version "$COMPONENT") + fi + log "Installing version: $VERSION" + + # Get tag name + local tag_name + tag_name=$(get_tag_name "$COMPONENT" "$VERSION") + log "Using release tag: $tag_name" + + # Install binary + install_binary "$COMPONENT" "$platform" "$tag_name" + + log "โœ… Installation complete!" + echo + + # Show component-specific next steps + if [[ "$COMPONENT" == "mitosisd" ]]; then + log "๐ŸŽฏ Next steps for Mitosis Chain Node:" + echo " 1. Initialize your node: mitosisd init [moniker] --chain-id mitosis-mainnet-1" + echo " 2. Start the node: mitosisd start" + echo " 3. Check version: mitosisd version" + echo " 4. View logs: mitosisd start --log_level info" + else + log "๐ŸŽฏ Next steps for Mito CLI:" + echo " 1. Configure RPC: mito config set-rpc https://rpc.mitosis.org" + echo " 2. Set contracts: mito config set-contract --validator-manager 0x..." + echo " 3. Check version: mito version" + echo " 4. View help: mito --help" + fi + + echo + log "๐Ÿ“– Documentation: https://docs.mitosis.org" + log "๐Ÿ’ฌ Community: https://discord.gg/mitosis" + + # Show installation info for other component + if [[ "$COMPONENT" == "mitosisd" ]]; then + echo + log "๐Ÿ’ก To install the Mito CLI separately:" + echo " COMPONENT=mito curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash" + else + echo + log "๐Ÿ’ก To install the Mitosis Chain Node separately:" + echo " curl -sSL https://raw.githubusercontent.com/mitosis-org/chain/main/scripts/install.sh | bash" + fi +} + +# Run main function +main "$@" \ No newline at end of file