Skip to content

Commit

Permalink
feat: mfx-migrator alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
fmorency authored Mar 18, 2024
1 parent 17e1957 commit 8ddc81e
Show file tree
Hide file tree
Showing 49 changed files with 8,648 additions and 8 deletions.
17 changes: 10 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
# The Lifted Initiative
version: 2.1

GO_VERSION: &go_version '1.22'
GORELEASER_VERSION: &goreleaser_version 'v1.23.0'
GO_VERSION: &go_version '1.22.1'
GORELEASER_VERSION: &goreleaser_version 'v1.24.0'

orbs:
go: circleci/go@1.10.0
codecov: codecov/codecov@3.3.0
go: circleci/go@1.11.0
codecov: codecov/codecov@4.0.1

jobs:
build:
executor:
name: go/default
tag: *go_version
machine:
image: ubuntu-2204:current
resource_class: large
steps:
- checkout
- go/install:
version: *go_version
- go/load-cache
- go/mod-download
- go/save-cache
- run: make test
- run: make coverage
- codecov/upload:
file: coverage-filtered.out
Expand Down
Empty file added .coverageignore
Empty file.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# IDE files
.idea/

# Build files
dist/

# OS files
.DS_Store
Thumbs.db
53 changes: 53 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

project_name: mfx-migrator

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- main: ./main.go
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
ignore:
- goos: darwin
goarch: amd64
- goos: linux
goarch: arm64

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- .Version }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
Empty file added LICENSE
Empty file.
114 changes: 114 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#### HELP ####

help: ## Display this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: help

#### BUILD ####

build: ## Build the project
@echo "--> Building project"
@go build -o mfx-migrator ./
@echo "--> Building project complete"

.PHONY: build

#### CLEAN ####

clean: ## Clean the project
@echo "--> Cleaning project"
@go clean
@echo "--> Cleaning project complete"

.PHONY: clean

#### INSTALL ####

install: ## Install the project
@echo "--> Installing project"
@go install
@echo "--> Installing project complete"

.PHONY: install

#### LINT ####

golangci_version=latest

lint-install:
@echo "--> Installing golangci-lint $(golangci_version)"
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(golangci_version)
@echo "--> Installing golangci-lint $(golangci_version) complete"

lint: ## Run linter (golangci-lint)
@echo "--> Running linter"
$(MAKE) lint-install
@golangci-lint run ./...

lint-fix:
@echo "--> Running linter"
$(MAKE) lint-install
@golangci-lint run ./... --fix

.PHONY: lint lint-fix

#### FORMAT ####

goimports_version=latest

format-install:
@echo "--> Installing goimports $(goimports_version)"
@go install golang.org/x/tools/cmd/goimports@$(goimports_version)
@echo "--> Installing goimports $(goimports_version) complete"

format: ## Run formatter (goimports)
@echo "--> Running goimports"
$(MAKE) format-install
@find . -name '*.go' -exec goimports -w -local github.com/liftedinit/mfx-migrator {} \;

#### GOVULNCHECK ####
govulncheck_version=latest

govulncheck-install:
@echo "--> Installing govulncheck $(govulncheck_version)"
@go install golang.org/x/vuln/cmd/govulncheck@$(govulncheck_version)
@echo "--> Installing govulncheck $(govulncheck_version) complete"

govulncheck: ## Run govulncheck
@echo "--> Running govulncheck"
$(MAKE) govulncheck-install
@govulncheck ./...

#### VET ####

vet: ## Run go vet
@echo "--> Running go vet"
@go vet ./...

.PHONY: vet

#### COVERAGE ####

coverage: ## Run coverage report
@echo "--> Running coverage"
@go test -race -cpu=$$(nproc) -covermode=atomic -coverprofile=coverage.out $$(go list ./...) ./interchaintest/... -coverpkg=github.com/liftedinit/mfx-migrator/... > /dev/null 2>&1
@echo "--> Running coverage filter"
@./scripts/filter-coverage.sh
@echo "--> Running coverage report"
@go tool cover -func=coverage-filtered.out
@echo "--> Running coverage html"
@go tool cover -html=coverage-filtered.out -o coverage.html
@echo "--> Coverage report available at coverage.html"
@echo "--> Cleaning up coverage files"
@rm coverage.out
@echo "--> Running coverage complete"

.PHONY: coverage

#### TEST ####

test: ## Run tests
@echo "--> Running tests"
@go test -race -cpu=$$(nproc) $$(go list ./...) ./interchaintest/...

.PHONY: test
99 changes: 98 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,98 @@
# mfx-migrator
**mfx-migrator** is a centralized daemon responsible for migrating data from the old MANY chain to the new MANIFEST chain.
The daemon analyses the MANY chain for new migration-type transactions, processed them, and triggers token transaction on the MANIFEST chain.

This software is not for external use.

The complete migration flow is as follows:
1. The user performs a migration transaction on the MANY chain using Alberto's Token Migration Portal.
2. The transaction is processed by the MANY chain.
3. The `Talib` block explorer picks up the transaction and stores it in its database.
4. The `mfx-migrator` daemon claim new work items from the `Talib` database.
5. The `mfx-migrator` daemon processes the work item and triggers a token transaction on the MANIFEST chain.
6. The transaction is processed by the MANIFEST chain.
7. The `mfx-migrator` daemon updates the work item status in the `Talib` database.

# Requirements

- Go programming language, version 1.22.1 or higher
- GNU Make
- Bash
- (Optional) Docker (for running the E2E tests)

# How to use

This section describes how to use the `mfx-migrator` software.

Global flags:
- `-l, --logLevel string` - Set the log level. Possible values are `debug`, `info`, `warn`, and `error`. Default is `info`.
- `--neighborghood uint` - The neighborhood ID to use. Default is 0.
- `--password string` - The password to use for the remote database auth. Default is an empty string.
- `--url string` - The root URL of the remote database API. Default is an empty string.
- `--username string` - The username to use for the remote database auth. Default is an empty string.

## Claim a work item

To claim a work item, run the following command:

```bash
mfx-migrator claim
```

Optional flags:
- `--force` - Force the claim of a work item regardless of its status.
- `--uuid string` - Claim a specific work item by UUID.

This command claims a work item from the remote database and store it in a file in the current directory.
The file is named `[UUID].json`, where `[UUID]` is the UUID of the work item.
The work item will be locked to prevent other workers from claiming it.

## Migrate a work item

To migrate a claimed work item, run the following command:

```bash
mfx-migrator migrate [UUID]
```
where `[UUID]` is the UUID of the work item.

Flags:
- `--address-prefix string` - Address prefix of the MANIFEST chain. Default is `manifest`.
- `--bank-address string` - The address of the bank account to use for the token transaction on the MANIFEST chain. Default is `bank`.
- `--chain-home` - The root directory of the chain configuration. Default is an empty string.
- `--chain-id string` - The chain ID of the MANIFEST chain. Default is `manifest-1`.
- `--keyring-backend string` - The keyring backend to use. Default is `test`.
- `--node-address` - The RPC endpoint of the MANIFEST chain. Default is `http://localhost:26657`.
- `--uuid string` - The UUID of the work item to migrate. Default is an empty string.

This command triggers a token transaction on the MANIFEST chain and updates the work item status in the remote database.

## Verify a work item

To verify a work item, run the following command:

```bash
mfx-migrator verify [UUID]
```
where `[UUID]` is the UUID of the work item.

Flags:
- `--uuid string` - The UUID of the work item to verify. Default is an empty string.

This command verifies the status of the work item in the remote database.

# Developers

Use the provided `Makefile` to execute common operations

```shell
help Display this help screen
build Build the project
clean Clean the project
install Install the project
lint Run linter (golangci-lint)
format Run formatter (goimports)
govulncheck Run govulncheck
vet Run go vet
coverage Run coverage report
test Run tests
```
Loading

0 comments on commit 8ddc81e

Please sign in to comment.