Majority dynamics on trees and the dynamic cavity method