Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Export actions.jsonl, enable with --write-actions ... works in boot a…
Browse files Browse the repository at this point in the history
…nd join.
  • Loading branch information
abourget committed May 29, 2018
1 parent 5a10484 commit c2593ac
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
62 changes: 54 additions & 8 deletions bios/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type BIOS struct {
TargetNetAPI *eos.API
Snapshot Snapshot
BootSequence []*OperationType
WriteActions bool

Genesis *GenesisJSON

Expand Down Expand Up @@ -231,13 +232,6 @@ func (b *BIOS) PrintProducerSchedule(orderedPeers []*Peer) {
func (b *BIOS) RunBootSequence() error {
b.Log.Println("START BOOT SEQUENCE...")

// keys, _ := b.TargetNetAPI.Signer.(*eos.KeyBag).AvailableKeys()
// for _, key := range keys {
// b.Log.Println("Available key in the KeyBag:", key)
// }

// Update boot sequence HERE

ephemeralPrivateKey, err := b.GenerateEphemeralPrivKey()
if err != nil {
return err
Expand All @@ -258,6 +252,10 @@ func (b *BIOS) RunBootSequence() error {
return fmt.Errorf("ImportWIF: %s", err)
}

if err := b.writeAllActionsToDisk(); err != nil {
return fmt.Errorf("writing actions to disk: %s", err)
}

genesisData := b.GenerateGenesisJSON(pubKey.String())

if len(b.Network.MyPeer.Discovery.SeedNetworkPeers) > 0 && !b.SingleOnly {
Expand Down Expand Up @@ -375,7 +373,10 @@ func (b *BIOS) RunJoinNetwork(validate, sabotage bool) error {
}
b.EphemeralPublicKey = pubKey

// Create mesh network
if err := b.writeAllActionsToDisk(); err != nil {
return fmt.Errorf("writing actions to disk: %s", err)
}

otherPeers := b.computeMyMeshP2PAddresses()

if err := b.DispatchJoinNetwork(b.Genesis, b.getMyPeerVariations(), otherPeers); err != nil {
Expand Down Expand Up @@ -456,6 +457,51 @@ func (b *BIOS) RunChainValidation() (bool, error) {
return true, nil
}

func (b *BIOS) writeAllActionsToDisk() error {
if !b.WriteActions {
fmt.Println("Not writing actions to 'actions.jsonl'. Activate with --write-actions")
return nil
}

fmt.Println("Writing all actions to 'actions.jsonl'...")
fl, err := os.Create("actions.jsonl")
if err != nil {
return err
}
defer fl.Close()

for _, step := range b.BootSequence {
if b.LaunchDisco.TargetNetworkIsTest == 0 {
step.Data.ResetTestnetOptions()
}

acts, err := step.Data.Actions(b)
if err != nil {
return fmt.Errorf("fetch step %q: %s", step.Op, err)
}

for _, stepAction := range acts {
if stepAction == nil {
continue
}

stepAction.SetToServer(false)
data, err := json.Marshal(stepAction)
if err != nil {
return fmt.Errorf("binary marshalling: %s", err)
}

_, err = fl.Write(data)
if err != nil {
return err
}
_, _ = fl.Write([]byte("\n"))
}
}

return nil
}

type ActionMap map[string]*eos.Action

type ValidationError struct {
Expand Down
4 changes: 3 additions & 1 deletion eos-bios/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,7 @@ func setupBIOS(net *bios.Network) (b *bios.BIOS, err error) {
targetNetAPI := eos.New(targetNetHTTP)
targetNetAPI.SetSigner(eos.NewKeyBag())

return bios.NewBIOS(net.Log, net, targetNetAPI), nil
b = bios.NewBIOS(net.Log, net, targetNetAPI)
b.WriteActions = viper.GetBool("write-actions")
return b, nil
}
3 changes: 2 additions & 1 deletion eos-bios/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ func init() {
RootCmd.PersistentFlags().StringP("seednet-keys", "", "./seed_network.keys", "File containing private keys to your account on the seed network")
RootCmd.PersistentFlags().StringP("target-api", "", "", "HTTP address to reach the node you are starting (for injection and validation)")

RootCmd.PersistentFlags().BoolP("write-actions", "", false, "Write actions to actions.jsonl upon join or boot")
RootCmd.PersistentFlags().StringP("cache-path", "", filepath.Join(homedir, ".eos-bios-cache"), "directory to store cached data from discovered network")
RootCmd.PersistentFlags().BoolP("verbose", "v", false, "Display verbose output (also see 'output.log')")
RootCmd.PersistentFlags().String("elect", "", "Force the election of the given BIOS Boot node")

for _, flag := range []string{"cache-path", "my-discovery", "ipfs", "seednet-keys", "seednet-api", "target-api", "verbose", "elect"} {
for _, flag := range []string{"cache-path", "my-discovery", "ipfs", "seednet-keys", "write-actions", "seednet-api", "target-api", "verbose", "elect"} {
if err := viper.BindPFlag(flag, RootCmd.PersistentFlags().Lookup(flag)); err != nil {
panic(err)
}
Expand Down

0 comments on commit c2593ac

Please sign in to comment.