gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source.
https://gno.land/
Other
892 stars 371 forks source link

Map package variable breaks the contract execution without exception #311

Closed piux2 closed 1 year ago

piux2 commented 2 years ago
package maptest

var m = make(map[string]string)

func Deposit() string{
  m["0xABC"] = "10ugnot"
  return "Deposited"
}

The maptest contract does not return anything when Deposit() is called a second time. The contract seems to have stopped executing before the return but no panic or exception.

moul commented 2 years ago

Golang's team intentionally made it random, starting with Go 1, to make developers not rely on it. See https://go.dev/blog/maps.

Protobuf also specifies that they have fewer guarantees and implements them as slices of structs on the wire.

And on a side note, some web2 CTO friends added linters to prevent their teams from using maps. Even in web2, indeterministic maps were too confusing with flappy unit tests or bugs discovered in production. They told me that maps are generally deficient in performance, not only in go. But please, keep this comment as a hint and not a fact.


My current feeling: