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

Fix: Solve issue #331 by adding FirstEvent support in FireFly config #332

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

MKVEERENDRA
Copy link

This PR addresses issue #331, which was about adding support for the FirstEvent parameter in the FireFly configuration files.

Changes Made:
Added a new FirstEvent field support in the FireFly configuration (firefly_core_*.yml) files to allow specifying the starting event for blockchain-based processes.
Integrated this new parameter into the FireFly configuration logic during the stack initialization process.
Updated the stack setup and blockchain deployment flow to support FirstEvent, ensuring it can be configured when setting up FireFly for the first time.
The FirstEvent field is now configurable in the FireFlyConfig and is passed to the blockchain and smart contract initialization process.
Context and Fix:
The addition of the FirstEvent parameter gives users flexibility in defining which blockchain event the FireFly stack should use when starting up. This was missing in the previous configuration, causing issues for users who needed specific event handling.
This update ensures that FirstEvent is properly handled, stored in the configuration, and used during smart contract and blockchain node setup.
How to Test:
Start the FireFly stack with the new configuration changes.
Verify that the FirstEvent field is correctly passed to the blockchain during FireFly stack initialization.
Ensure that the expected event triggers the FireFly workflow appropriately, depending on the FirstEvent configuration value.
Issue Comment (on issue #331):
I have solved issue #331 by adding support for the FirstEvent parameter in the FireFly configuration. This allows users to specify which event should be used during FireFly stack initialization, enabling more flexible event handling for blockchain-based processes.

The fix is now available in the pull request https://github.com/MKVEERENDRA/firefly-cli1, and it has been tested to ensure the correct configuration of the FirstEvent value during the FireFly setup.

@MKVEERENDRA
Copy link
Author

I Fixed it

cmd/start.go Outdated
@@ -104,5 +104,6 @@ This command will start a stack and run it in the background.

func init() {
startCmd.Flags().BoolVarP(&startOptions.NoRollback, "no-rollback", "b", false, "Do not automatically rollback changes if first time setup fails")
startCmd.Flags().StringVarP(&startOptions.FirstEvent, "first-event", "f", "0", "Specify the starting block for event processing (default: 0)")
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things:

  • Move this to the init command
  • Would suggest renaming to --from-block and I wouldn't put a shortcut for this one of -f
  • I would make this super obvious that is only applies to multiparty as a contract listener gets created for that contract... It might be better as well to not create the contract listener at all
Suggested change
startCmd.Flags().StringVarP(&startOptions.FirstEvent, "first-event", "f", "0", "Specify the starting block for event processing (default: 0)")
startCmd.Flags().StringVarP(&startOptions.FirstEvent, "--from-block", "f", "0", "Specify the starting block for event processing (default: 0)")

if err := s.patchFireFlyCoreConfigs(configDir, member, newConfig); err != nil {
return messages, err
}
if s.Stack.MultipartyEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

Indentation looks odd

Copy link
Contributor

Choose a reason for hiding this comment

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

and not sure why code was removed to write to the state file her

for _, member := range s.Stack.Members {
orgConfig := s.blockchainProvider.GetOrgConfig(s.Stack, member)
newConfig.Namespaces.Predefined[0].DefaultKey = orgConfig.Key
if s.Stack.MultipartyEnabled {
Copy link
Contributor

Choose a reason for hiding this comment

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

we still need this MultipartyEnabled wrapping this section


for _, member := range s.Stack.Members {
orgConfig := s.blockchainProvider.GetOrgConfig(s.Stack, member)
newConfig.Namespaces.Predefined[0].DefaultKey = orgConfig.Key
Copy link
Contributor

Choose a reason for hiding this comment

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

need this key as well

internal/stacks/stack_manager.go Outdated Show resolved Hide resolved
@MKVEERENDRA
Copy link
Author

I did what you said can you pls check out the commit

Copy link
Contributor

@EnriqueL8 EnriqueL8 left a comment

Choose a reason for hiding this comment

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

Quite a few comments, and see many problems with the structure of the code and the types. Please do add some tests and try this out. Keep the comments that were previously put in by other contributors when the logic has not changed.

When initializing a new stack, you can configure various options including:

```
--from-block For multiparty networks only: specify the starting block for event processing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should only work with remote-node-url as with the local chain that the CLI creates we want to start from 0

Copy link
Contributor

Choose a reason for hiding this comment

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

as it should point to when the contract was deployed - I'm more tempted for this to be --contract-block as you pass in the MultiParty Contract address through --contract

Comment on lines +70 to +77
# Initialize with default settings (starts from block 0)
ff init mystack

# Initialize starting from the latest block
ff init mystack --from-block newest

# Initialize starting from a specific block number
ff init mystack --from-block 1234567
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make these examples to be with --emote-node-url set

@@ -102,6 +102,9 @@ This command will start a stack and run it in the background.
},
}


// ... existing code ...
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this

@@ -611,44 +610,44 @@ func (s *StackManager) createMember(id string, index int, options *types.InitOpt

func (s *StackManager) StartStack(options *types.StartOptions) (messages []string, err error) {
fmt.Printf("starting FireFly stack '%s'... ", s.Stack.Name)
// Check to make sure all of our ports are available

// Check port availability
Copy link
Contributor

Choose a reason for hiding this comment

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

why the comment change?

@@ -864,7 +863,7 @@ func checkPortAvailable(port int) (bool, error) {
}

//nolint:gocyclo // TODO: Breaking this function apart would be great for code tidiness, but it's not an urgent priority
func (s *StackManager) runFirstTimeSetup(options *types.StartOptions) (messages []string, err error) {
func (s *StackManager) runFirstTimeSetup(options *types.InitOptions) (messages []string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should still be the StartOptions

Comment on lines -946 to -964
// TODO: This code assumes that there is only one plugin instance per type. When we add support for
// multiple namespaces, this code will likely have to change a lot
s.Log.Info("deploying FireFly smart contracts")
contractDeploymentResult, err = s.blockchainProvider.DeployFireFlyContract()
if err != nil {
return messages, err
}
if contractDeploymentResult != nil {
if contractDeploymentResult.Message != "" {
messages = append(messages, contractDeploymentResult.Message)
}
s.Stack.State.DeployedContracts = append(s.Stack.State.DeployedContracts, contractDeploymentResult.DeployedContract)
}
}
}

for _, member := range s.Stack.Members {
orgConfig := s.blockchainProvider.GetOrgConfig(s.Stack, member)
newConfig.Namespaces.Predefined[0].DefaultKey = orgConfig.Key
Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned in my previous review, keep this code as it was

Comment on lines +626 to +628
setupMessages, err := s.runFirstTimeSetup(&types.InitOptions{
FromBlock: options.FromBlock,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

FromBlock doesn't exist in InitOptions, it should be StartOptions. Getting errors in the IDE

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.

2 participants