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

Commit

Permalink
Split actions in transactions more properly.. the chain likes that be…
Browse files Browse the repository at this point in the history
…tter

and times out less often.

Attempt at improving `invite`.. don't
  • Loading branch information
abourget committed May 19, 2018
1 parent 3a02dc7 commit 8eb8f93
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 56 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ TODO
launcher would have that key.. well it would have been
published.. so anyone really would have access to that (!!).

* Only download the IPFS refs from the top X that can take the
decision.. so we're not slowed down by some who never push their
files.

* p2p chain validation.. should wait until the `target_p2p_address` is
reachable.. not fail right away.. and retry.

* Insert a `nil` eos.Action in the `Actions()` to split the transactions.. so that
Transfer and NewAccount are not in the same.


Role Seed Account Target Acct Weight Contents Launch block (local time)
---- ------------ ----------- ------ ---------------- ------------
Expand Down
20 changes: 14 additions & 6 deletions bios/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (b *BIOS) RunBootSequence() error {
}

if len(acts) != 0 {
for idx, chunk := range chunkifyActions(acts, 8) { // transfers max out resources higher than ~400
for idx, chunk := range chunkifyActions(acts) { // transfers max out resources higher than ~400
err := retry(25, time.Second, func() error {
_, err := b.TargetNetAPI.SignPushActions(chunk...)
if err != nil {
Expand All @@ -305,8 +305,9 @@ func (b *BIOS) RunBootSequence() error {
fmt.Printf(" error\n")
return err
}
fmt.Printf(" done\n")
fmt.Printf(".")
}
fmt.Printf(" done\n")
}
}

Expand Down Expand Up @@ -416,6 +417,10 @@ func (b *BIOS) RunChainValidation() (bool, error) {
}

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

data, err := eos.MarshalBinary(stepAction)
if err != nil {
return false, fmt.Errorf("verifying: binary marshalling: %s", err)
Expand Down Expand Up @@ -839,14 +844,17 @@ func (b *BIOS) setMyPeers() error {
return nil
}

func chunkifyActions(actions []*eos.Action, chunkSize int) (out [][]*eos.Action) {
func chunkifyActions(actions []*eos.Action) (out [][]*eos.Action) {
currentChunk := []*eos.Action{}
for _, act := range actions {
if len(currentChunk) > chunkSize {
out = append(out, currentChunk)
if act == nil {
if len(currentChunk) != 0 {
out = append(out, currentChunk)
}
currentChunk = []*eos.Action{}
} else {
currentChunk = append(currentChunk, act)
}
currentChunk = append(currentChunk, act)
}
if len(currentChunk) > 0 {
out = append(out, currentChunk)
Expand Down
14 changes: 7 additions & 7 deletions bios/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ func (op *OpCreateProducers) Actions(b *BIOS) (out []*eos.Action, err error) {
// fmt.Println("Some JSON", string(mama))

fmt.Printf("- Creating new account %q\n", prodName)
out = append(out, newAccount, buyRAMBytes, delegateBW)
out = append(out, newAccount, buyRAMBytes, delegateBW, nil)

if op.TestnetEnrichProducers {
fmt.Printf(" DEBUG: Enriching producer %q\n", prodName)
out = append(out, token.NewTransfer(AN("eosio"), prodName, eos.NewEOSAsset(1000000000), "Hey, make good use of it!"))
out = append(out, token.NewTransfer(AN("eosio"), prodName, eos.NewEOSAsset(1000000000), "Hey, make good use of it!"), nil)
}
}
return
Expand All @@ -247,7 +247,7 @@ func (op *OpRegisterProducers) Actions(b *BIOS) (out []*eos.Action, err error) {
}
regprod := system.NewRegProducer(prodName, prod.Discovery.TargetAppointedBlockProducerSigningKey, url) // overridden just below
regprod.Authorization[0].Actor = AN("eosio")
out = append(out, regprod)
out = append(out, regprod, nil)
}
return
}
Expand Down Expand Up @@ -306,6 +306,7 @@ func (op *OpSnapshotCreateAccounts) Actions(b *BIOS) (out []*eos.Action, err err
out = append(out, system.NewDelegateBW(AN("eosio"), destAccount, firstHalf, secondHalf, false))

out = append(out, system.NewBuyRAMBytes(AN("eosio"), destAccount, uint32(op.BuyRAM)))
out = append(out, nil) // end transaction

if trunc := op.TestnetTruncateSnapshot; trunc != 0 {
if idx == trunc {
Expand Down Expand Up @@ -358,7 +359,7 @@ func (op *OpSnapshotTransfer) Actions(b *BIOS) (out []*eos.Action, err error) {
}

memo := "Welcome " + hodler.EthereumAddress[len(hodler.EthereumAddress)-6:]
out = append(out, token.NewTransfer(AN("eosio"), destAccount, hodler.Balance, memo))
out = append(out, token.NewTransfer(AN("eosio"), destAccount, hodler.Balance, memo), nil)

if trunc := op.TestnetTruncateSnapshot; trunc != 0 {
if idx == trunc {
Expand Down Expand Up @@ -403,7 +404,7 @@ func (op *OpInjectUnregdSnapshot) Actions(b *BIOS) (out []*eos.Action, err error

fmt.Printf("Preparing %d actions to honor crowdsale buyers that did not register. This is a provision for the future\n", len(snapshotData))
for idx, hodler := range snapshotData {
out = append(out, unregd.NewAdd(hodler.EthereumAddress, hodler.Balance))
out = append(out, unregd.NewAdd(hodler.EthereumAddress, hodler.Balance), nil)

if trunc := op.TestnetTruncateSnapshot; trunc != 0 {
if idx == trunc {
Expand Down Expand Up @@ -484,9 +485,8 @@ func (op *OpDestroyAccounts) Actions(b *BIOS) (out []*eos.Action, err error) {
},
},
}, PN("owner")),
// TODO: add recovery here ??
nil, // end transaction
)

// unregister the producer at the same time ?
}
return
Expand Down
48 changes: 5 additions & 43 deletions eos-bios/cmd/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var inviteCmd = &cobra.Command{
Short: "Invite a fellow block producer to the seed network where you have access to",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
net, err := fetchNetwork(false, false)
net, err := fetchNetwork(true, false)
if err != nil {
log.Fatalln("fetch network:", err)
}
Expand All @@ -42,9 +42,7 @@ var inviteCmd = &cobra.Command{
os.Exit(1)
}

fmt.Println("")
fmt.Printf("Creating account %q with public key %q, using my account %q\n", args[0], args[1], net.MyPeer.Discovery.SeedNetworkAccountName)
fmt.Println("")
fmt.Printf("Creating account %q with public key %q, using my account %q, on network %q\n", args[0], args[1], net.MyPeer.Discovery.SeedNetworkAccountName, net.MyPeer.Discovery.SeedNetworkHTTPAddress)

_, err = net.SeedNetAPI.SignPushActions(
system.NewNewAccount(
Expand All @@ -59,52 +57,16 @@ var inviteCmd = &cobra.Command{
system.NewDelegateBW(
eos.AccountName(net.MyPeer.Discovery.SeedNetworkAccountName),
eos.AccountName(args[0]),
eos.NewEOSAsset(1000),
eos.NewEOSAsset(1000),
eos.NewEOSAsset(10000),
eos.NewEOSAsset(10000),
false,
),
/* "actions": [
{
"account": "eosio",
"name": "newaccount",
"authorization": [
{
"actor": "eoscanadacom",
"permission": "active"
}
],
"data": "202932c94c833055000000d3757730550100000001000264d39e1bb1fc7f2519046f1c35329f49e21c832eb3fd00a0b1e3433b2323d8b7010000000100000001000264d39e1bb1fc7f2519046f1c35329f49e21c832eb3fd00a0b1e3433b2323d8b701000000"
},
{
"account": "eosio",
"name": "buyrambytes",
"authorization": [
{
"actor": "eoscanadacom",
"permission": "active"
}
],
"data": "202932c94c833055000000d37577305500200000"
},
{
"account": "eosio",
"name": "delegatebw",
"authorization": [
{
"actor": "eoscanadacom",
"permission": "active"
}
],
"data": "202932c94c833055000000d375773055102700000000000004454f5300000000102700000000000004454f530000000001"
}
],
*/
)
if err != nil {
log.Fatalln("creating account:", err)
}

fmt.Println("Done.")
fmt.Println("Done. Now transfer them some EOS so they can invite others too.")
},
}

Expand Down

0 comments on commit 8eb8f93

Please sign in to comment.