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

add rhs/onchain resolvers #12

Merged
merged 27 commits into from
Feb 6, 2024
Merged

add rhs/onchain resolvers #12

merged 27 commits into from
Feb 6, 2024

Conversation

volodymyr-basiuk
Copy link
Contributor

No description provided.

Copy link
Contributor

@ilya-korotya ilya-korotya left a comment

Choose a reason for hiding this comment

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

Why does this one thread code have mutex?

go.mod Show resolved Hide resolved
resolvers/onchain.go Show resolved Hide resolved
resolvers/onchain.go Outdated Show resolved Hide resolved
resolvers/onchain.go Outdated Show resolved Hide resolved
resolvers/onchain.go Show resolved Hide resolved
resolvers/onchain.go Outdated Show resolved Hide resolved
resolvers/onchain.go Outdated Show resolved Hide resolved
resolvers/onchain.go Outdated Show resolved Hide resolved
// OnChainResolverConfig options for credential status verification
type OnChainResolverConfig struct {
EthClients map[core.ChainID]*ethclient.Client
StateContractAddr common.Address
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have map[stateContractAddr]*ethclinet.Client

Copy link
Contributor

Choose a reason for hiding this comment

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

no, chainID - client.

return new(big.Int).SetBytes(utils.SwapEndianness(bs))
}

func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It is very psycho function 💂‍♂️
Why do you use mutex here and have duplicate code to get id, but one getter uses Readmutex but another uses FullLockMutext

idsInStateContractLock.RLock()
	ok := idsInStateContract[*id]
	idsInStateContractLock.RUnlock()
	if ok {
		return ok, nil
	}

	idsInStateContractLock.Lock()
	defer idsInStateContractLock.Unlock()

	ok = idsInStateContract[*id]
	if ok {
		return ok, nil
	}

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

https://en.wikipedia.org/wiki/Readers–writer_lock
https://en.wikipedia.org/wiki/Double-checked_locking
@ilya-korotya If this pattern is not clear to you after reading this, please ping me. I'll try to describe it with reference to this code.

But in this case, the double-check pattern is a bad idea because we perform a long operation when getting data from the network. I'll rewrite it.

@iden3 iden3 deleted a comment from ilya-korotya Feb 5, 2024
olomix
olomix previously approved these changes Feb 5, 2024
func newChainIDFromString(in string) (core.ChainID, error) {
var chainID uint64
var err error
if strings.HasPrefix(in, "0x") ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer not to rely on the implementation of the ParseUint function. We support a chainID either in the format of decimal or hex. I don't think it is a good idea to encourage users to set the chain ID as 0b10101 or 0o123.

resolvers/onchain.go Outdated Show resolved Hide resolved
return newIntFromBytesLE(stateBytes), nil
}

func newIntFromBytesLE(bs []byte) *big.Int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

-1

For me, it has the advantage of readability. I understand the author's intentions where it is used. Instead, I should interpret the meaning of this 'one line' to understand what it does.

return new(big.Int).SetBytes(utils.SwapEndianness(bs))
}

func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

https://en.wikipedia.org/wiki/Readers–writer_lock
https://en.wikipedia.org/wiki/Double-checked_locking
@ilya-korotya If this pattern is not clear to you after reading this, please ping me. I'll try to describe it with reference to this code.

But in this case, the double-check pattern is a bad idea because we perform a long operation when getting data from the network. I'll rewrite it.


func stateContractHasID(ctx context.Context, stateAddr common.Address, ethClient *ethclient.Client, id *core.ID) (bool, error) {

idsInStateContractLock.RLock()
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok

go.mod Show resolved Hide resolved
olomix
olomix previously approved these changes Feb 5, 2024
ilya-korotya
ilya-korotya previously approved these changes Feb 6, 2024
@ilya-korotya ilya-korotya self-requested a review February 6, 2024 15:33
@vmidyllic vmidyllic merged commit 63e8bb0 into main Feb 6, 2024
3 checks passed
@vmidyllic vmidyllic deleted the feature/status-resolvers branch February 6, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants