-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat(f3): manifest retrieval from smart contract #5321
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f27db8d
feat(f3): manifest retrieval from smart contract
hanabi1224 e6587af
refactor
hanabi1224 c27d3e0
Merge remote-tracking branch 'origin/main' into hm/f3-contract-manife…
hanabi1224 92155c6
ContractManifestProvider
hanabi1224 4bcf84d
Merge remote-tracking branch 'origin/main' into hm/f3-contract-manife…
hanabi1224 3425568
fix
hanabi1224 1de2414
Merge branch 'main' into hm/f3-contract-manifest-integration
hanabi1224 711b988
Merge remote-tracking branch 'origin/main' into hm/f3-contract-manife…
hanabi1224 d8c055c
Merge branch 'main' into hm/f3-contract-manifest-integration
hanabi1224 b81c4b3
Update src/rpc/methods/f3.rs
hanabi1224 edb93e4
FOREST_F3_CONTRACT_ADDRESS env var
hanabi1224 b4b9b45
fix spellcheck errors
hanabi1224 cc8e25e
link to solidity contract
hanabi1224 627b492
Merge remote-tracking branch 'origin/main' into hm/f3-contract-manife…
hanabi1224 7de05ce
link to activationInformation method ID
hanabi1224 76edefb
Update src/rpc/methods/f3/types.rs
hanabi1224 6789916
no indexing_slicing
hanabi1224 c94730c
go mod tidy
hanabi1224 8ee02b8
Merge remote-tracking branch 'origin/main' into hm/f3-contract-manife…
hanabi1224 83ca6db
enable F3 on mainnet
hanabi1224 c083f09
Merge branch 'main' into hm/f3-contract-manifest-integration
hanabi1224 cd97d98
fix
hanabi1224 cc981f1
Merge branch 'main' into hm/f3-contract-manifest-integration
hanabi1224 220b177
Merge branch 'main' into hm/f3-contract-manifest-integration
hanabi1224 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-f3/manifest" | ||
) | ||
|
||
type ContractManifestProvider struct { | ||
started *bool | ||
pollInterval time.Duration | ||
initialManifest *manifest.Manifest | ||
currentManifest *manifest.Manifest | ||
f3Api *F3Api | ||
ch chan *manifest.Manifest | ||
} | ||
|
||
func NewContractManifestProvider(initialValue *manifest.Manifest, contract_manifest_poll_interval_seconds uint64, f3Api *F3Api) (*ContractManifestProvider, error) { | ||
if err := initialValue.Validate(); err != nil { | ||
return nil, err | ||
} | ||
started := false | ||
pollInterval := time.Duration(contract_manifest_poll_interval_seconds) * time.Second | ||
p := ContractManifestProvider{ | ||
started: &started, | ||
pollInterval: pollInterval, | ||
initialManifest: initialValue, | ||
currentManifest: nil, | ||
f3Api: f3Api, | ||
ch: make(chan *manifest.Manifest), | ||
} | ||
return &p, nil | ||
} | ||
|
||
func (p *ContractManifestProvider) Update(m *manifest.Manifest) { | ||
p.currentManifest = m | ||
p.ch <- m | ||
} | ||
|
||
func (p *ContractManifestProvider) Start(ctx context.Context) error { | ||
if *p.started { | ||
logger.Warnf("ContractManifestProvider has already been started\n") | ||
return nil | ||
} | ||
|
||
started := true | ||
p.started = &started | ||
go func() { | ||
for started && ctx.Err() == nil { | ||
if p.currentManifest == nil { | ||
p.Update(p.initialManifest) | ||
} | ||
logger.Debugf("Polling manifest from contract...\n") | ||
m, err := p.f3Api.GetManifestFromContract(ctx) | ||
if err == nil { | ||
if m != nil { | ||
if !m.Equal(p.currentManifest) { | ||
logger.Infof("Successfully polled manifest from contract, updating...\n") | ||
p.Update(m) | ||
} else { | ||
logger.Infof("Successfully polled unchanged manifest from contract\n") | ||
} | ||
} | ||
} else { | ||
logger.Warnf("failed to get manifest from contract: %s\n", err) | ||
} | ||
time.Sleep(p.pollInterval) | ||
} | ||
}() | ||
|
||
return nil | ||
} | ||
func (p *ContractManifestProvider) Stop(context.Context) error { | ||
*p.started = false | ||
return nil | ||
} | ||
func (p *ContractManifestProvider) ManifestUpdates() <-chan *manifest.Manifest { return p.ch } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 not sure what are the best practices in Go, but would it make sense to check all pointer parameters in methods that they are not
nil
? There was recently anil
derefeence in go-f3.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.
In our case, the parameters are passed from Rust code which are not
nil
, the signature types that are generated byrust2go
are pointers to avoid lifetime issuesThere 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.
It might be helpful to comment on this somewhere, given it's not obvious (at least for me).
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.
Fixed.