Skip to content

Commit

Permalink
Merge pull request #86 from renproject/feat/integrate-terra
Browse files Browse the repository at this point in the history
Simplify database and transaction inputs + Terra integration
  • Loading branch information
jazg committed Oct 7, 2020
2 parents bdd267b + b3f7ec2 commit 7bfe23e
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 691 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.2.1
- Darknode transaction input compatibility updates
- Integrate Terra

## 0.2.0
- Darknode v0.3.0 compatibility

## 0.1.12
- Update transaction if Darknodes return a "done" status
- Increase default unconfirmed transaction expiry to 14 days
Expand Down
23 changes: 11 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ ENV GO111MODULE=on
ARG GITHUB_TOKEN
RUN git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"

# Download dependencies.
WORKDIR /lightnode
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy the code into the container.
COPY . .

# Download Filecoin dependencies
RUN apt-get autoclean
RUN apt-get update
RUN apt-get install -y jq
RUN apt-get install -y ocl-icd-opencl-dev
RUN git submodule add --force https://github.com/filecoin-project/filecoin-ffi.git extern/filecoin-ffi
WORKDIR /lightnode/extern/filecoin-ffi
RUN git clone https://github.com/filecoin-project/filecoin-ffi.git /extern/filecoin-ffi
WORKDIR /extern/filecoin-ffi
RUN git checkout 777a6fbf4446b1112adfd4fa5dd88e0c88974122
RUN make

# Download dependencies.
WORKDIR /lightnode
RUN go mod edit -replace=github.com/filecoin-project/filecoin-ffi=./extern/filecoin-ffi
COPY go.mod .
COPY go.sum .
RUN go mod download

# Copy the code into the container.
COPY . .
RUN go mod edit -replace=github.com/filecoin-project/filecoin-ffi=../extern/filecoin-ffi

# Build the code inside the container.
RUN go build ./cmd/lightnode
Expand Down
6 changes: 6 additions & 0 deletions cmd/lightnode/lightnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ func parseOptions() lightnode.Options {
},
}
}
if os.Getenv("RPC_TERRA") != "" {
chains[multichain.Terra] = txenginebindings.ChainOptions{
RPC: pack.String(os.Getenv("RPC_TERRA")),
Confirmations: pack.U64(parseInt(os.Getenv("CONFIRMATIONS_TERRA"))),
}
}
if os.Getenv("RPC_ZCASH") != "" {
chains[multichain.Zcash] = txenginebindings.ChainOptions{
RPC: pack.String(os.Getenv("RPC_ZCASH")),
Expand Down
29 changes: 13 additions & 16 deletions confirmer/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/renproject/darknode/txengine"
"github.com/renproject/lightnode/db"
"github.com/renproject/lightnode/http"
"github.com/renproject/multichain"
"github.com/renproject/pack"
"github.com/renproject/phi"
)
Expand Down Expand Up @@ -87,9 +88,10 @@ func (confirmer *Confirmer) checkPendingTxs(parent context.Context) {
phi.ParForAll(txs, func(i int) {
tx := txs[i]
var confirmed bool
if tx.Selector.IsLockAndMint() {
switch {
case tx.Selector.IsLock():
confirmed = confirmer.lockTxConfirmed(ctx, tx)
} else {
case tx.Selector.IsBurn():
confirmed = confirmer.burnTxConfirmed(ctx, tx)
}

Expand Down Expand Up @@ -136,25 +138,24 @@ func (confirmer *Confirmer) confirm(ctx context.Context, transaction tx.Tx) {
// lockTxConfirmed checks if a given lock transaction has received sufficient
// confirmations.
func (confirmer *Confirmer) lockTxConfirmed(ctx context.Context, transaction tx.Tx) bool {
lockChain, ok := transaction.Selector.LockChain()
if !ok {
confirmer.options.Logger.Errorf("[confirmer] cannot get lock chain for tx=%v (%v)", transaction.Hash.String(), transaction.Selector.String())
return false
}
lockChain := transaction.Selector.Source()
switch {
case lockChain.IsUTXOBased():
input := txengine.InputLockOnUTXOAndMintOnAccount{}
input := txengine.Input{}
if err := pack.Decode(&input, transaction.Input); err != nil {
confirmer.options.Logger.Errorf("[confirmer] failed to decode input for tx=%v: %v", transaction.Hash.String(), err)
return false
}
_, err := confirmer.bindings.UTXOLockInfo(ctx, lockChain, transaction.Selector.Asset(), input.Output.Outpoint)
_, err := confirmer.bindings.UTXOLockInfo(ctx, lockChain, transaction.Selector.Asset(), multichain.UTXOutpoint{
Hash: input.Txid,
Index: input.Txindex,
})
if err != nil {
confirmer.options.Logger.Errorf("[confirmer] cannot get output for utxo tx=%v (%v): %v", input.Output.Outpoint.Hash.String(), transaction.Selector.String(), err)
confirmer.options.Logger.Errorf("[confirmer] cannot get output for utxo tx=%v (%v): %v", input.Txid.String(), transaction.Selector.String(), err)
return false
}
case lockChain.IsAccountBased():
input := txengine.InputLockOnAccountAndMintOnAccount{}
input := txengine.Input{}
if err := pack.Decode(&input, transaction.Input); err != nil {
confirmer.options.Logger.Errorf("[confirmer] failed to decode input for tx=%v: %v", transaction.Hash.String(), err)
return false
Expand All @@ -173,11 +174,7 @@ func (confirmer *Confirmer) lockTxConfirmed(ctx context.Context, transaction tx.
// burnTxConfirmed checks if a given burn transaction has received sufficient
// confirmations.
func (confirmer *Confirmer) burnTxConfirmed(ctx context.Context, transaction tx.Tx) bool {
burnChain, ok := transaction.Selector.BurnChain()
if !ok {
confirmer.options.Logger.Errorf("[confirmer] cannot get burn chain for tx=%v (%v)", transaction.Hash.String(), transaction.Selector.String())
return false
}
burnChain := transaction.Selector.Source()
nonce, ok := transaction.Input.Get("nonce").(pack.Bytes32)
if !ok {
confirmer.options.Logger.Errorf("[confirmer] failed to get nonce for tx=%v", transaction.Hash.String())
Expand Down
Loading

0 comments on commit 7bfe23e

Please sign in to comment.