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

An optimization suggestion about transaction serialization #161

Open
shniu opened this issue Apr 9, 2024 · 0 comments
Open

An optimization suggestion about transaction serialization #161

shniu opened this issue Apr 9, 2024 · 0 comments

Comments

@shniu
Copy link

shniu commented Apr 9, 2024

I have some questions about the following code:

// Serialize pack tx into byte array
func (tx *Transaction) Serialize() ([]byte, error) {
	if len(tx.Signatures) == 0 || len(tx.Signatures) != int(tx.Message.Header.NumRequireSignatures) {
		return nil, errors.New("Signature verification failed")
	}

	signatureCount := bincode.UintToVarLenBytes(uint64(len(tx.Signatures)))
	messageData, err := tx.Message.Serialize()
	if err != nil {
		return nil, err
	}
     
        // ?? Why does here use **len(signatureCount)*64** ??
	output := make([]byte, 0, len(signatureCount)+len(signatureCount)*64+len(messageData))
	output = append(output, signatureCount...)
	for _, sig := range tx.Signatures {
		output = append(output, sig...)
	}
	output = append(output, messageData...)

	return output, nil
}

This line output := make([]byte, 0, len(signatureCount)+len(signatureCount)*64+len(messageData)), i think it makes more sense to use len(tx.Signatures) * 64 here.

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

No branches or pull requests

1 participant