-
Notifications
You must be signed in to change notification settings - Fork 10
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
l1 chain #1219
l1 chain #1219
Conversation
create index nonces_l1_chain_idx on nonces (address,chain,l1_chain); | ||
create index wallets_l1_chain_idx on wallets (address,chain,l1_chain); | ||
create unique index wallets_l1_chain_unique_idx on wallets (address,l1_chain) where deleted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to remove any of the current indexes, specifically the unique ones on (address,chain)
? I imagined we still would want them because we still need those two to be unique (despite them always being unique given we correctly use the l1_chain, e.g. there will be no case where two rows with (addr: 0x9, ch: BASE)
and (addr:0x9, ch: BASE)
getting through because they will always fail on (addr: 0x9, l1_ch: ETH)
anyway). I imagine leaving them would not hurt us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of leaving it for now! I think your point is spot-on: we shouldn't need it, assuming we're getting the L1 chain correct...but the wallets table is relatively small, the extra index doesn't cost us much, and I like the peace of mind in knowing that we can't accidentally end up in a situation that should be impossible.
// Insert inserts a wallet by its address and chain | ||
func (w *WalletRepository) Insert(ctx context.Context, chainAddress persist.ChainAddress, walletType persist.WalletType) (persist.DBID, error) { | ||
|
||
_, err := w.insertStmt.ExecContext(ctx, persist.GenerateID(), 0, chainAddress.Address(), chainAddress.Chain(), walletType) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// rather than using the ID generated above, we must retrieve it because in the case of conflict the ID above would be inaccurate. | ||
wa, err := w.GetByChainAddress(ctx, chainAddress) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return wa.ID, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused
- column: '*.*.chain' | ||
go_type: 'github.com/mikeydub/go-gallery/service/persist.Chain' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome, Benny! I really like how this turned out, and I think it's going to simplify a lot of the L1 chain issues we've been running into!
update wallets set l1_chain = 4 where chain = 4; | ||
|
||
create index nonces_l1_chain_idx on nonces (address,chain,l1_chain); | ||
create index wallets_l1_chain_idx on wallets (address,chain,l1_chain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the non-unique indexes here would also benefit from where deleted = false
create index nonces_l1_chain_idx on nonces (address,chain,l1_chain); | ||
create index wallets_l1_chain_idx on wallets (address,chain,l1_chain); | ||
create unique index wallets_l1_chain_unique_idx on wallets (address,l1_chain) where deleted = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of leaving it for now! I think your point is spot-on: we shouldn't need it, assuming we're getting the L1 chain correct...but the wallets table is relatively small, the extra index doesn't cost us much, and I like the peace of mind in knowing that we can't accidentally end up in a situation that should be impossible.
and w.id = any(u.wallets) and coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) = w.address | ||
and c.chain = w.chain | ||
and w.id = any(u.wallets) and coalesce(nullif(c.owner_address, ''), nullif(c.creator_address, '')) = w.address | ||
and w.chain = any(@l1_chains::int[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, this makes me think we should add the l1_chain
column to the contracts
table, too. That way, we can say "give me contracts on any(@chains)
where the user owns a wallet on the contract's L1 chain," which is (I think) the most correct way to phrase this query.
...but also, that would add some pretty significant scope to this PR, and I don't think it's necessary to add it for the sake of this one query. I think your current workaround is good here, but we should definitely add l1_chain
to contracts in the near future!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, was thinking this as well when I had to make this little work around. If we do contracts, might as well do tokens too at some point...
@@ -22,6 +22,8 @@ type UserNonce struct { | |||
LastUpdated time.Time `json:"last_updated"` | |||
Value NullString `json:"value"` | |||
Address Address `json:"address"` | |||
Chain Chain `json:"chain"` | |||
L1Chain Chain `json:"l1_chain"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a new type for L1Chain
instead of repurposing Chain
? IMHO we wouldn't want to accept an L1Chain
anywhere we'd accept a regular Chain
, or vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
checkNoErr(err) | ||
|
||
getByIDStmt, err := db.PrepareContext(ctx, `SELECT ID,VERSION,CREATED_AT,LAST_UPDATED,ADDRESS,WALLET_TYPE,CHAIN FROM wallets WHERE ID = $1 AND DELETED = FALSE;`) | ||
getByChainAddressStmt, err := db.PrepareContext(ctx, `SELECT ID,VERSION,CREATED_AT,LAST_UPDATED,ADDRESS,WALLET_TYPE,CHAIN,L1_CHAIN FROM wallets WHERE ADDRESS = $1 AND L1_CHAIN = $2 AND DELETED = FALSE;`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the concept of an L1ChainAddress
that uses L1Chain
instead of a regular chain? It's starting to feel that way to me! A query named getByChainAddress
makes me think we'll be passing in a Chain
, but we're actually using an L1Chain
here, and it'd probably make the codebase clearer if we separated those concepts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure!
Changes:
l1_chain
column towallets
andnonces
table.l1_chain
WalletOverrides
to live in persist instead of wire injection