Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove the alphMinConfirmations flag #77

Merged
merged 2 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 0 additions & 130 deletions bridge_ui/src/components/AlephiumCreateLocalTokenPool.tsx

This file was deleted.

24 changes: 1 addition & 23 deletions bridge_ui/src/components/Attest/Create.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CHAIN_ID_ALEPHIUM, CHAIN_ID_TERRA } from "@alephium/wormhole-sdk";
import { CHAIN_ID_TERRA } from "@alephium/wormhole-sdk";
import { CircularProgress, makeStyles } from "@material-ui/core";
import { useSelector } from "react-redux";
import useFetchForeignAsset from "../../hooks/useFetchForeignAsset";
Expand All @@ -7,15 +7,12 @@ import useIsWalletReady from "../../hooks/useIsWalletReady";
import {
selectAttestSourceAsset,
selectAttestSourceChain,
selectAttestSignedVAAHex,
selectAttestTargetChain,
} from "../../store/selectors";
import ButtonWithLoader from "../ButtonWithLoader";
import KeyAndBalance from "../KeyAndBalance";
import TerraFeeDenomPicker from "../TerraFeeDenomPicker";
import WaitingForWalletMessage from "./WaitingForWalletMessage";
import { useCallback, useEffect, useState } from "react";
import AlephiumCreateLocalTokenPool from "../AlephiumCreateLocalTokenPool";

const useStyles = makeStyles((theme) => ({
alignCenter: {
Expand Down Expand Up @@ -44,17 +41,6 @@ function Create() {
const { handleClick, disabled, showLoader } = useHandleCreateWrapped(
shouldUpdate || false
);
const signedVAAHex = useSelector(selectAttestSignedVAAHex)
const [isConfirmOpen, setIsConfirmOpen] = useState(false)
useEffect(() => {
setIsConfirmOpen(signedVAAHex !== undefined)
}, [signedVAAHex])
const handleConfirmClick = useCallback(() => {
setIsConfirmOpen(false);
}, []);
const handleConfirmClose = useCallback(() => {
setIsConfirmOpen(false);
}, []);

return (
<>
Expand All @@ -69,14 +55,6 @@ function Create() {
</>
) : (
<>
{originChain === CHAIN_ID_ALEPHIUM && !shouldUpdate && (
<AlephiumCreateLocalTokenPool
open={isConfirmOpen}
signedVAAHex={signedVAAHex}
onClick={handleConfirmClick}
onClose={handleConfirmClose}
/>
)}
<ButtonWithLoader
disabled={!isReady || disabled}
onClick={handleClick}
Expand Down
68 changes: 64 additions & 4 deletions bridge_ui/src/components/Attest/Send.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
import { CHAIN_ID_ALEPHIUM, CHAIN_ID_SOLANA, CHAIN_ID_TERRA } from "@alephium/wormhole-sdk";
import { CHAIN_ID_ALEPHIUM, CHAIN_ID_SOLANA, CHAIN_ID_TERRA, waitAlphTxConfirmed } from "@alephium/wormhole-sdk";
import { Alert } from "@material-ui/lab";
import { Link, makeStyles } from "@material-ui/core";
import { useMemo } from "react";
import { useSelector } from "react-redux";
import { useCallback, useMemo, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { useHandleAttest } from "../../hooks/useHandleAttest";
import useIsWalletReady from "../../hooks/useIsWalletReady";
import useMetaplexData from "../../hooks/useMetaplexData";
import {
selectAttestAttestTx,
selectAttestIsSendComplete,
selectAttestSignedVAAHex,
selectAttestSourceAsset,
selectAttestSourceChain,
selectAttestSourceChain
} from "../../store/selectors";
import ButtonWithLoader from "../ButtonWithLoader";
import KeyAndBalance from "../KeyAndBalance";
import TransactionProgress from "../TransactionProgress";
import WaitingForWalletMessage from "./WaitingForWalletMessage";
import { ALEPHIUM_ATTEST_TOKEN_CONSISTENCY_LEVEL, SOLANA_TOKEN_METADATA_PROGRAM_URL } from "../../utils/consts";
import TerraFeeDenomPicker from "../TerraFeeDenomPicker";
import { createLocalTokenPool } from "../../utils/alephium";
import { useWallet } from "@alephium/web3-react";
import { useSnackbar } from "notistack";
import { setStep } from "../../store/attestSlice";

const useStyles = makeStyles((theme) => ({
alert: {
Expand Down Expand Up @@ -53,9 +58,63 @@ const SolanaTokenMetadataWarning = () => {
) : null;
};

function CreateLocalTokenPool({ localTokenId }: { localTokenId: string }) {
const alphWallet = useWallet()
const dispatch = useDispatch()
const { enqueueSnackbar } = useSnackbar()
const signedVAAHex = useSelector(selectAttestSignedVAAHex)
const [isSending, setIsSending] = useState<boolean>(false)
const [error, setError] = useState<string | undefined>()
const onClick = useCallback(async () => {
if (signedVAAHex !== undefined && alphWallet?.nodeProvider !== undefined) {
try {
setIsSending(true)
const createLocalTokenPoolTxId = await createLocalTokenPool(
alphWallet.signer,
alphWallet.nodeProvider,
alphWallet.account.address,
localTokenId,
Buffer.from(signedVAAHex, 'hex')
)
if (createLocalTokenPoolTxId !== undefined) {
await waitAlphTxConfirmed(alphWallet.nodeProvider, createLocalTokenPoolTxId, 1)
console.log(`create local token pool tx id: ${createLocalTokenPoolTxId}`)
enqueueSnackbar(null, {
content: <Alert severity="success">Transaction confirmed</Alert>
})
} else {
enqueueSnackbar(null, {
content: <Alert severity="info">Local token pool already exists</Alert>
})
}
} catch (error) {
setError(`${error}`)
}

setIsSending(false)
dispatch(setStep(3))
}
}, [alphWallet, signedVAAHex, enqueueSnackbar, localTokenId, dispatch])
const isReady = signedVAAHex !== undefined && alphWallet !== undefined && !isSending

return (
<>
<ButtonWithLoader
disabled={!isReady}
onClick={onClick}
showLoader={isSending}
error={error}
>
{isSending ? 'Waiting for transaction confirmation...' : 'Create Local Token Pool'}
</ButtonWithLoader>
</>
)
}

function Send() {
const { handleClick, disabled, showLoader } = useHandleAttest();
const sourceChain = useSelector(selectAttestSourceChain);
const sourceAsset = useSelector(selectAttestSourceAsset);
const attestTx = useSelector(selectAttestAttestTx);
const isSendComplete = useSelector(selectAttestIsSendComplete);
const { isReady, statusMessage } = useIsWalletReady(sourceChain);
Expand All @@ -82,6 +141,7 @@ function Send() {
isSendComplete={isSendComplete}
consistencyLevel={sourceChain === CHAIN_ID_ALEPHIUM ? ALEPHIUM_ATTEST_TOKEN_CONSISTENCY_LEVEL : undefined}
/>
{ sourceChain === CHAIN_ID_ALEPHIUM && <CreateLocalTokenPool localTokenId={sourceAsset}/> }
</>
);
}
Expand Down
4 changes: 3 additions & 1 deletion bridge_ui/src/store/attestSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export const attestSlice = createSlice({
state.signedVAAHex = action.payload;
state.isSending = false;
state.isWalletApproved = false;
state.activeStep = 3;
if (state.sourceChain !== CHAIN_ID_ALEPHIUM) {
state.activeStep = 3;
}
},
setIsSending: (state, action: PayloadAction<boolean>) => {
state.isSending = action.payload;
Expand Down
10 changes: 4 additions & 6 deletions node/cmd/guardiand/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ var (
// solanaWsRPC *string
// solanaRPC *string

alphRPC *string
alphApiKey *string
alphMinConfirmations *uint8
alphPollInterval *uint8
alphRPC *string
alphApiKey *string
alphPollInterval *uint8

logLevel *string

Expand Down Expand Up @@ -218,7 +217,6 @@ func init() {

alphRPC = NodeCmd.Flags().String("alphRPC", "", "Alephium RPC URL (required)")
alphApiKey = NodeCmd.Flags().String("alphApiKey", "", "Alphium RPC api key")
alphMinConfirmations = NodeCmd.Flags().Uint8("alphMinConfirmations", 1, "The min confirmations for alephium tx")
alphPollInterval = NodeCmd.Flags().Uint8("alphPollInterval", 4, "The poll interval of alephium watcher")

logLevel = NodeCmd.Flags().String("logLevel", "info", "Logging level (debug, info, warn, error, dpanic, panic, fatal)")
Expand Down Expand Up @@ -690,7 +688,7 @@ func runNode(cmd *cobra.Command, args []string) {

alphWatcher, err := alephium.NewAlephiumWatcher(
*alphRPC, *alphApiKey, alphConfig, common.ReadinessAlephiumSyncing,
lockC, *alphMinConfirmations, *alphPollInterval, chainObsvReqC[vaa.ChainIDAlephium],
lockC, *alphPollInterval, chainObsvReqC[vaa.ChainIDAlephium],
)
if err != nil {
logger.Error("failed to create alephium watcher", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion node/pkg/alephium/reobserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (w *Watcher) getGovernanceEventsByTxId(

reobservedEvents = append(reobservedEvents, &reobservedEvent{
&event,
maxUint8(msg.consistencyLevel, w.minConfirmations),
msg.consistencyLevel,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR: how do we enforce the minimum consistencyLevel for new messages from users?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we enforce the minimum consistency level in both frontend and contract:

  1. The frontend sets the consistencyLevel to 105 when the user sends a transaction
  2. We also check in the contract that the consistencyLevel for the transfer transaction is not less than 105

header,
txId,
})
Expand Down
11 changes: 4 additions & 7 deletions node/pkg/alephium/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ type Watcher struct {
msgChan chan *common.MessagePublication
obsvReqC chan *gossipv1.ObservationRequest

minConfirmations uint8
pollInterval uint8
currentHeight int32
pollInterval uint8
currentHeight int32

client *Client
}
Expand All @@ -92,7 +91,6 @@ func NewAlephiumWatcher(
chainConfig *common.ChainConfig,
readiness readiness.Component,
messageEvents chan *common.MessagePublication,
minConfirmations uint8,
pollInterval uint8,
obsvReqC chan *gossipv1.ObservationRequest,
) (*Watcher, error) {
Expand Down Expand Up @@ -121,8 +119,7 @@ func NewAlephiumWatcher(
msgChan: messageEvents,
obsvReqC: obsvReqC,

minConfirmations: minConfirmations,
pollInterval: pollInterval,
pollInterval: pollInterval,

client: NewClient(url, apiKey, 10),
}
Expand Down Expand Up @@ -374,7 +371,7 @@ func (w *Watcher) handleEvents_(
remain := make([]*UnconfirmedEvent, 0)
logger.Info("processing events from block", zap.String("blockHash", blockEvents.header.Hash), zap.Int("size", len(blockEvents.events)))
for _, event := range blockEvents.events {
eventConfirmations := maxUint8(event.msg.consistencyLevel, w.minConfirmations)
eventConfirmations := event.msg.consistencyLevel
if blockEvents.header.Height+int32(eventConfirmations) > height {
logger.Debug(
"event not confirmed",
Expand Down
Loading